Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
add dialog if a geometry generated by the plugin is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Jul 15, 2019
1 parent 09403e0 commit c10bb9f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions label_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import ntpath
from PyQt5.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, QUrl
from PyQt5.QtGui import QIcon, QColor, QDesktopServices
from PyQt5.QtWidgets import QAction, QToolBar, QToolButton
from PyQt5.QtWidgets import QAction, QToolBar, QToolButton, QMessageBox
from PyQt5 import QtXml
from qgis.core import (QgsMapLayer, QgsGeometryGeneratorSymbolLayer, QgsSymbol, QgsPalLayerSettings,
QgsPropertyCollection, QgsProperty, QgsPropertyDefinition, QgsVectorLayerSimpleLabeling,
QgsRenderContext, QgsMarkerSymbol, QgsLineSymbol, QgsFillSymbol, QgsRuleBasedRenderer, QgsWkbTypes, QgsSettings)

from qgis.gui import QgsNewAuxiliaryLayerDialog

# Initialize Qt resources from file resources.py
Expand Down Expand Up @@ -377,8 +377,6 @@ def applyStyle(self, expressionFile):
self.createDefinedProperties()

if self.addSymbol(expr) == False:
self.messageBar.pushCritical(self.tr("LabelConnector already exists"), self.tr(
"If you want to add a new LabelConnector on the style, please remove the comment in the geometry generator expression first in style properties."))
# delete created style
styleManager.removeStyle(
styleManager.currentStyle())
Expand Down Expand Up @@ -406,9 +404,22 @@ def applyStyle(self, expressionFile):
return True

def isSymbolContainsLabelConnector(self, symbol):
found = False
for sl in symbol.symbolLayers():
if type(sl) is QgsGeometryGeneratorSymbolLayer and sl.geometryExpression().find("/* Generated by LabelConnector plugin") == 0:
found = True
break

if found:
ret = QMessageBox.question(
None,
"LabelConnector already exists",
"Do you want to add a new LabelConnector on the style?"
)
if ret != QMessageBox.Yes:
# The symbol contains already a LabelConector
return True

return False

def addSymbol(self, expression):
Expand Down Expand Up @@ -462,6 +473,5 @@ def addSymbol(self, expression):
return True

def runHelp(self):
QDesktopServices.openUrl(QUrl("https://github.com/Oslandia/labelconnector/blob/master/help/help.md#{}-documentation-du-plugin-labelconnector".format(QSettings().value('locale/userLocale')[0:2])))


QDesktopServices.openUrl(QUrl(
"https://github.com/Oslandia/labelconnector/blob/master/help/help.md#{}-documentation-du-plugin-labelconnector".format(QSettings().value('locale/userLocale')[0:2])))

0 comments on commit c10bb9f

Please sign in to comment.