simplify icon

This commit is contained in:
nobohan 2021-07-13 11:47:27 +02:00
parent ca258bc445
commit 04af3c1884
6 changed files with 24 additions and 91 deletions

1
plot_layout/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

View File

@ -9,6 +9,7 @@ from qgis.PyQt.QtWidgets import (
QPushButton,
QVBoxLayout
)
from qgis.PyQt.QtGui import QIcon
from qgis.gui import (
QgsLayoutItemAbstractGuiMetadata,
QgsLayoutItemBaseWidget,
@ -17,9 +18,7 @@ from qgis.gui import (
from qgis.core import ( QgsLayoutItemRegistry )
from plot_settings_widget import DataPlotlyPanelWidget
from gui_utils import GuiUtils
# from plot_settings_widget import DataPlotlyPanelWidget
ITEM_TYPE = QgsLayoutItemRegistry.PluginItem + 1338
@ -268,10 +267,11 @@ class PlotLayoutItemGuiMetadata(QgsLayoutItemAbstractGuiMetadata):
"""
def __init__(self):
super().__init__(ITEM_TYPE, 'test')
super().__init__(ITEM_TYPE, 'layoutItemGui')
def creationIcon(self): # pylint: disable=missing-docstring, no-self-use
return GuiUtils.get_icon('circle.svg')
icon_path = ':/plugins/plot_layout/icon.png'
return QIcon(icon_path)
def createItemWidget(self, item): # pylint: disable=missing-docstring, no-self-use
return PlotLayoutItemWidget(None, item)

View File

@ -1,64 +0,0 @@
# -*- coding: utf-8 -*-
"""GUI Utilities
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import os
from qgis.PyQt.QtGui import QIcon
class GuiUtils:
"""
Utilities for GUI plugin components
"""
@staticmethod
def get_icon(icon: str) -> QIcon:
"""
Returns a plugin icon
:param icon: icon name (svg file name)
:return: QIcon
"""
path = GuiUtils.get_icon_svg(icon)
if not path:
return QIcon()
return QIcon(path)
@staticmethod
def get_icon_svg(icon: str) -> str:
"""
Returns a plugin icon's SVG file path
:param icon: icon name (svg file name)
:return: icon svg path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'icons',
icon)
if not os.path.exists(path):
return ''
return path
@staticmethod
def get_ui_file_path(file: str) -> str:
"""
Returns a UI file's path
:param file: file name (uifile name)
:return: ui file path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'ui',
file)
if not os.path.exists(path):
return ''
return path

View File

@ -15,31 +15,27 @@ class PlotLayoutItem(QgsLayoutItem):
def __init__(self, layout):
super().__init__(layout)
# self.setCacheMode(QGraphicsItem.NoCache)
# self.plot_settings = []
# self.plot_settings.append(PlotSettings())
# self.linked_map_uuid = ''
# self.linked_map = None
# self.filter_by_map = False
# self.filter_by_atlas = False
def draw(self, context):
pass
# if not self.html_loaded:
# self.load_content()
# self.web_page = LoggingWebPage(self)
# self.web_page.setNetworkAccessManager(QgsNetworkAccessManager.instance())
# if not self.layout().renderContext().isPreviewRender():
# # this is NOT safe to do when rendering in the gui (i.e. a preview render), but for exports we have
# # to loop around until the HTML has fully loaded
# while not self.html_loaded:
# QCoreApplication.processEvents()
# # This makes the background transparent. (copied from QgsLayoutItemLabel)
# palette = self.web_page.palette()
# palette.setBrush(QPalette.Base, Qt.transparent)
# self.web_page.setPalette(palette)
# self.web_page.mainFrame().setZoomFactor(10.0)
# self.web_page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
# self.web_page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
# # almost a direct copy from QgsLayoutItemLabel!
# painter = context.renderContext().painter()
# painter.save()
# self.web_page.loadFinished.connect(self.loading_html_finished)
# self.html_loaded = False
# self.html_units_to_layout_units = self.calculate_html_units_to_layout_units()
# self.sizePositionChanged.connect(self.refresh)
# # painter is scaled to dots, so scale back to layout units
# painter.scale(context.renderContext().scaleFactor() / self.html_units_to_layout_units,
# context.renderContext().scaleFactor() / self.html_units_to_layout_units)
# self.web_page.mainFrame().render(painter)
# painter.restore()
def type(self):
return ITEM_TYPE
@ -47,7 +43,7 @@ class PlotLayoutItem(QgsLayoutItem):
class PlotLayoutItemMetadata(QgsLayoutItemAbstractMetadata):
def __init__(self):
super().__init__(ITEM_TYPE, 'test')
super().__init__(ITEM_TYPE, 'layoutItem')
def createItem(self, layout):
return PlotLayoutItem(layout)