Ejemplo n.º 1
0
    def testGSNameWidgetValidName(self):
        nw = GSNameWidget(name='my_pg_connection')
        self.assertTrue(nw.isValid())
        self.assertIsNotNone(nw.definedName())
        self.assertEqual(nw.definedName(), 'my_pg_connection')

        nw.validateName('my_pg_connection')
        self.assertTrue(nw.isValid())
        nw.highlightName()
        self.assertEqual(nw.nameBox.lineEdit().styleSheet(), '')

        validnames = [
            'name_8291', 'name.with.dots', 'name:with::colons',
            '_name_with_underscore'
        ]

        # XML valid name
        nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg())
        self.assertTrue(nw.isValid())
        for vname in validnames:
            nw.setName(vname)
            self.assertTrue(nw.isValid())

        # empty name regex
        nw.setName('')
        nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg())
        self.assertTrue(nw.isValid())
        nw.setAllowEmpty(True)
        self.assertTrue(nw.isValid())
        self.assertEqual(nw.definedName(), '')
        for vname in validnames:
            nw.setName(vname)
            self.assertTrue(nw.isValid())
Ejemplo n.º 2
0
    def testGSNameWidgetNames(self):
        nw = GSNameWidget(
            name='name_one',
            names=['name_one', 'name_two', 'name_three'],
            unique=True)
        self.assertFalse(nw.isValid())

        nw.setNames(['name_four', 'name_five'])
        self.assertTrue(nw.isValid())
        self.assertEqual(nw.nameBox.count(), 3)  # 'name_one' prepended to list
        self.assertEqual(nw.definedName(), 'name_one')
        nw.setName('name_four')
        self.assertFalse(nw.isValid())
        self.assertIsNone(nw.definedName())

        nw.setName('name')
        nw.setNames(['name_one', 'name_two', 'name_three'])
        self.assertTrue(nw.isValid())
        self.assertEqual(nw.nameBox.count(), 4)  # 'name' is prepended to list
        self.assertEqual(nw.definedName(), 'name')

        nw.setNames([])
        self.assertTrue(nw.isValid())
        self.assertEqual(nw.nameBox.count(), 1)  # 'name' is prepended to list
        self.assertEqual(nw.definedName(), 'name')
Ejemplo n.º 3
0
    def testGSNameWidgetInvalidName(self):
        # base invalid name is empty
        nw = GSNameWidget(name='')
        self.assertFalse(nw.isValid())

        nw.validateName('')
        self.assertFalse(nw.isValid())
        nw.highlightName()
        self.assertNotEqual(nw.nameBox.lineEdit().styleSheet(), '')

        invalidnames = ['xMl_name', 'name with spaces', '9starts_with_number',
                        ':starts_with_punctuation']

        # XML invalid name
        nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg())
        self.assertFalse(nw.isValid())
        self.assertIsNone(nw.definedName())
        for ivname in invalidnames:
            nw.setName(ivname)
            self.assertFalse(nw.isValid())

        # empty name regex
        nw.setName('')
        nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg())
        self.assertTrue(nw.isValid())
        self.assertEqual(nw.definedName(), '')
        for ivname in invalidnames:
            nw.setName(ivname)
            self.assertFalse(nw.isValid())

        # custom regex invalid name
        nw.setNameRegex(r'^(?!XML|\d|\W)[a-z](\S(?!::))*', 'regex message')
        nw.setName('my::name')
        self.assertFalse(nw.isValid())
Ejemplo n.º 4
0
    def setTableContent(self):
        styles = self.catalog.get_styles()
        workspaces = self.catalog.get_workspaces()
        self.table.setRowCount(len(self.layers))
        catlayers = [lyr.name for lyr in self.catalog.get_layers()]
        for idx, layer in enumerate(self.layers):

            lyritem = QtGui.QTableWidgetItem(layer.name())
            lyritem.setToolTip(layer.name())
            lyritem.setFlags(QtCore.Qt.ItemIsEnabled
                             | QtCore.Qt.ItemIsUserCheckable)
            lyritem.setCheckState(QtCore.Qt.Unchecked)
            self.table.setItem(idx, self.getColumn(self.lyr), lyritem)

            nameBox = GSNameWidget(name=xmlNameFixUp(layer.name()),
                                   nameregex=xmlNameRegex(),
                                   nameregexmsg=xmlNameRegexMsg(),
                                   names=catlayers,
                                   unique=False)
            self.table.setCellWidget(idx, self.getColumn(self.name), nameBox)
            nameBox.setSizePolicy(
                QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Fixed))
            styleNames = ["[Use QGIS Style]"]
            self.nameBoxes.append(nameBox)

            overwriteBox = QtGui.QCheckBox()
            overwriteBox.setEnabled(False)
            overwriteBox.setToolTip("Overwrite existing layer")
            self.table.setCellWidget(idx, self.getColumn(self.ow),
                                     overwriteBox)

            nameBox.nameValidityChanged.connect(self.validateNames)
            nameBox.overwritingChanged[bool].connect(overwriteBox.setChecked)
            overwriteBox.setChecked(
                nameBox.overwritingName())  # initial update

            workspaceBox = QtGui.QComboBox()
            workspaceBox.setSizePolicy(
                QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Fixed))
            try:
                defaultWorkspace = self.catalog.get_default_workspace()
                defaultWorkspace.fetch()
                defaultName = defaultWorkspace.dom.find('name').text
            except:
                defaultName = None
            workspaceNames = [w.name for w in workspaces]
            workspaceBox.addItems(workspaceNames)
            if defaultName is not None:
                workspaceBox.setCurrentIndex(workspaceNames.index(defaultName))
            self.table.setCellWidget(idx, self.getColumn(self.wrksp),
                                     workspaceBox)

            stylesBox = QtGui.QComboBox()
            styleNames += [s.name for s in styles]
            stylesBox.addItems(styleNames)
            self.table.setCellWidget(idx, self.getColumn(self.style),
                                     stylesBox)
Ejemplo n.º 5
0
 def testGSNameWidgetMaxLenName(self):
     nw = GSNameWidget(name='my_pg_connection', maxlength=10)
     self.assertFalse(nw.isValid())
     nw.setName('my_pg_conn')
     self.assertTrue(nw.isValid())
     nw.setMaxLength(5)
     self.assertFalse(nw.isValid())
     nw.setMaxLength(10)
     self.assertTrue(nw.isValid())
Ejemplo n.º 6
0
 def testGSNameWidgetInit(self):
     nw = GSNameWidget(
         namemsg='Sample is generated from PostgreSQL connection name',
         name=xmlNameFixUp('My PG connection'),
         nameregex=xmlNameRegex(),
         nameregexmsg=xmlNameRegexMsg(),
         names=['name_one', 'name_two', 'name_three'],
         unique=False,
         maxlength=10)
     self.assertEqual(nw.nameBox.count(), 4)  # name is prepended to list
    def initGui(self):
        self.setWindowTitle('New workspace')
        verticalLayout = QtGui.QVBoxLayout()

        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setSpacing(30)
        horizontalLayout.setMargin(0)
        nameLabel = QtGui.QLabel('Workspace name')
        nameLabel.setMinimumWidth(150)
        self.nameBox = GSNameWidget(namemsg='',
                                    name='workspace',
                                    nameregex=xmlNameRegex(),
                                    nameregexmsg=xmlNameRegexMsg(),
                                    names=self.workspaces,
                                    unique=True,
                                    maxlength=10)
        self.nameBox.setMinimumWidth(250)
        horizontalLayout.addWidget(nameLabel)
        horizontalLayout.addWidget(self.nameBox)
        verticalLayout.addLayout(horizontalLayout)

        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setSpacing(30)
        horizontalLayout.setMargin(0)
        uriLabel = QtGui.QLabel('URI')
        uriLabel.setMinimumWidth(150)
        self.uriBox = QtGui.QLineEdit()
        self.uriBox.setText('')
        self.uriBox.setPlaceholderText('Required')
        self.uriBox.setMinimumWidth(250)
        horizontalLayout.addWidget(uriLabel)
        horizontalLayout.addWidget(self.uriBox)
        verticalLayout.addLayout(horizontalLayout)

        self.groupBox = QtGui.QGroupBox()
        self.groupBox.setLayout(verticalLayout)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.groupBox)
        self.spacer = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        layout.addItem(self.spacer)

        self.buttonBox = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
        self.okButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
        layout.addWidget(self.buttonBox)
        self.setLayout(layout)

        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)

        self.nameBox.nameValidityChanged.connect(self.updateOkButton)
        self.uriBox.textChanged.connect(self.updateOkButton)
        self.updateOkButton()
Ejemplo n.º 8
0
 def testGSNameWidgetUniqueName(self):
     nw = GSNameWidget(name='my_pg_connection',
                       names=['name_one', 'name_two', 'name_three'],
                       unique=False)
     self.assertTrue(nw.isValid())
     nw.setName('name_one')
     self.assertTrue(nw.isValid())
     self.assertTrue(nw.overwritingName())
     nw.setUnique(True)
     self.assertFalse(nw.isValid())
     self.assertFalse(nw.overwritingName())
     nw.setUnique(False)
     self.assertTrue(nw.isValid())
     self.assertTrue(nw.overwritingName())
Ejemplo n.º 9
0
 def __init__(self, boxtitle='', boxmsg='', name='', namemsg='',
              nameregex='', nameregexmsg='', names=None,
              unique=False, maxlength=0, parent=None):
     super(GSNameDialog, self).__init__(parent)
     self.boxtitle = boxtitle
     self.boxmsg = boxmsg
     self.nameBox = GSNameWidget(
         name=name,
         namemsg=namemsg,
         nameregex=nameregex,
         nameregexmsg=nameregexmsg,
         names=names,
         unique=unique,
         maxlength=maxlength
     )
     self.initGui()
Ejemplo n.º 10
0
    def initGui(self):
        verticalLayout = QtGui.QVBoxLayout()
        buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                           | QtGui.QDialogButtonBox.Close)
        self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok)
        self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close)
        self.setWindowTitle('Create style from layer')

        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setMargin(0)
        layerLabel = QtGui.QLabel('Layer')
        layerLabel.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                              QtGui.QSizePolicy.Fixed))
        self.layerBox = QtGui.QComboBox()
        self.alllayers = [layer.name() for layer in layers.getAllLayers()]
        self.layerBox.addItems(self.alllayers)
        self.layerBox.setMinimumWidth(250)
        horizontalLayout.addWidget(layerLabel)
        horizontalLayout.addWidget(self.layerBox)
        verticalLayout.addLayout(horizontalLayout)

        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setMargin(0)
        nameLabel = QtGui.QLabel('Name')
        nameLabel.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                              QtGui.QSizePolicy.Fixed))
        defaultname = ''
        if len(self.alllayers) > 0:
            defaultname = xmlNameFixUp(self.alllayers[0])
        self.nameBox = GSNameWidget(namemsg='',
                                    name=defaultname,
                                    nameregex=xmlNameRegex(),
                                    nameregexmsg=xmlNameRegexMsg(),
                                    names=self.styles,
                                    unique=False)
        self.nameBox.setMinimumWidth(250)
        horizontalLayout.addWidget(nameLabel)
        horizontalLayout.addWidget(self.nameBox)
        verticalLayout.addLayout(horizontalLayout)

        self.groupBox = QtGui.QGroupBox()
        self.groupBox.setTitle("")
        self.groupBox.setLayout(verticalLayout)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.groupBox)
        layout.addWidget(buttonBox)

        self.setLayout(layout)

        buttonBox.accepted.connect(self.okPressed)
        buttonBox.rejected.connect(self.cancelPressed)

        self.layerBox.currentIndexChanged[str].connect(self.updateNameBox)
        self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled)
        self.nameBox.overwritingChanged.connect(self.updateButtons)
        self.okButton.setEnabled(self.nameBox.isValid())
        self.updateButtons(self.nameBox.overwritingName())

        self.resize(400, 150)
Ejemplo n.º 11
0
    def initGui(self):
        verticalLayout = QtGui.QVBoxLayout()
        buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                           | QtGui.QDialogButtonBox.Close)
        self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok)
        self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close)
        self.setWindowTitle('Publish style')
        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setMargin(0)
        catalogLabel = QtGui.QLabel('Catalog')
        catalogLabel.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                              QtGui.QSizePolicy.Fixed))
        self.catalogBox = QtGui.QComboBox()
        self.catalogBox.addItems(self.catalognames)
        self.catalogBox.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Fixed))
        horizontalLayout.addWidget(catalogLabel)
        horizontalLayout.addWidget(self.catalogBox)
        verticalLayout.addLayout(horizontalLayout)

        horizontalLayout = QtGui.QHBoxLayout()
        horizontalLayout.setMargin(0)
        nameLabel = QtGui.QLabel('Name')
        nameLabel.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum,
                              QtGui.QSizePolicy.Fixed))
        self.nameBox = GSNameWidget(namemsg='',
                                    name=xmlNameFixUp(self.layername),
                                    nameregex=xmlNameRegex(),
                                    nameregexmsg=xmlNameRegexMsg(),
                                    names=[],
                                    unique=False)
        self.nameBox.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Fixed))
        horizontalLayout.addWidget(nameLabel)
        horizontalLayout.addWidget(self.nameBox)
        verticalLayout.addLayout(horizontalLayout)

        self.groupBox = QtGui.QGroupBox()
        self.groupBox.setTitle("")
        self.groupBox.setLayout(verticalLayout)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.groupBox)
        layout.addWidget(buttonBox)

        self.setLayout(layout)

        buttonBox.accepted.connect(self.okPressed)
        buttonBox.rejected.connect(self.cancelPressed)

        self.catalogBox.currentIndexChanged[str].connect(
            self.updateCatalogStyles)
        self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled)
        self.nameBox.overwritingChanged.connect(self.updateButtons)

        self.updateCatalogStyles(self.catalogBox.currentText())
        self.okButton.setEnabled(self.nameBox.isValid())
        self.updateButtons(self.nameBox.overwritingName())

        self.resize(400, 200)
Ejemplo n.º 12
0
    def setupUi(self):
        self.resize(600, 350)
        self.setWindowTitle("Group definition")
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setSpacing(2)
        self.verticalLayout.setMargin(6)
        self.horizontalLayout = QHBoxLayout()
        # self.horizontalLayout.setSpacing(30)
        self.horizontalLayout.setMargin(0)
        self.nameLabel = QLabel("Group name")
        self.nameLabel.setSizePolicy(
            QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred))
        defaultname = "Group"
        if self.previousgroup:
            defaultname = self.previousgroup.name
        self.nameBox = GSNameWidget(
            namemsg='',
            name=defaultname,
            nameregex=xmlNameRegex(),
            nameregexmsg=xmlNameRegexMsg(),
            names=self.groupnames,
            unique=False if self.previousgroup else True)
        if self.previousgroup:
            self.nameBox.setEnabled(False)
        self.nameBox.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred))

        self.horizontalLayout.addWidget(self.nameLabel)
        self.horizontalLayout.addWidget(self.nameBox)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setSpacing(6)
        self.horizontalLayout.setMargin(0)
        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(Qt.Vertical)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok)
        self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel)
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setColumnWidth(0, 300)
        self.table.verticalHeader().setVisible(False)
        self.table.horizontalHeader().setVisible(True)
        self.table.setHorizontalHeaderLabels(["Layer", "Style"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.selectAllButton = QPushButton()
        self.selectAllButton.setText("(de)Select all")
        self.setTableContent()
        self.buttonBox.addButton(self.selectAllButton,
                                 QDialogButtonBox.ActionRole)
        self.horizontalLayout.addWidget(self.table)
        self.horizontalLayout.addWidget(self.buttonBox)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.setLayout(self.verticalLayout)
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.selectAllButton.clicked.connect(self.selectAll)

        self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled)
        self.nameBox.overwritingChanged.connect(self.updateButtons)
        self.okButton.setEnabled(self.nameBox.isValid())
        self.updateButtons(self.nameBox.overwritingName())