Exemplo n.º 1
0
 def testGSNameStaticUtils(self):
     n = xmlNameFixUp('My PG connection')
     self.assertTrue(n == 'My_PG_connection')
     n = xmlNameFixUp('0Name_with_number')
     self.assertTrue(n == '_0Name_with_number')
     n = xmlNameFixUp('xml_starts_name')
     self.assertTrue(n == '_xml_starts_name')
     n = xmlNameFixUp(':Name_startswith_punctuation')
     self.assertTrue(n == '_:Name_startswith_punctuation')
     nr = xmlNameRegex()
     self.assertTrue(QRegExp(nr, 0).isValid())
     nrm = xmlNameRegexMsg()
     self.assertTrue('XML name' in nrm)
Exemplo n.º 2
0
 def testGSNameStaticUtils(self):
     n = xmlNameFixUp('My PG connection')
     self.assertTrue(n == 'My_PG_connection')
     n = xmlNameFixUp('0Name_with_number')
     self.assertTrue(n == '_0Name_with_number')
     n = xmlNameFixUp('xml_starts_name')
     self.assertTrue(n == '_xml_starts_name')
     n = xmlNameFixUp(':Name_startswith_punctuation')
     self.assertTrue(n == '_:Name_startswith_punctuation')
     nr = xmlNameRegex()
     self.assertTrue(QRegExp(nr, 0).isValid())
     nrm = xmlNameRegexMsg()
     self.assertTrue('XML name' in nrm)
Exemplo n.º 3
0
    def publishLayer(self,
                     layer,
                     workspace=None,
                     overwrite=True,
                     name=None,
                     style=None):
        '''
        Publishes a QGIS layer.
        It creates the corresponding store and the layer itself.
        If a pre-upload hook is set, its runs it and publishes the resulting layer

        layer: the layer to publish, whether as a QgsMapLayer object or its name in the QGIS TOC.

        workspace: the workspace to publish to. USes the default workspace if not passed
        or None

        name: the name for the published layer. Uses the QGIS layer name if not passed
        or None

        style: the style to use from the ones in the catalog. Will upload the QGIS style if
        not passed or None

        '''

        if isinstance(layer, basestring):
            layer = layers.resolveLayer(layer)

        addTrackedLayer(layer, self.catalog.service_url)

        name = xmlNameFixUp(name) if name is not None \
            else xmlNameFixUp(layer.name())

        gslayer = self.catalog.get_layer(name)
        if gslayer is not None and not overwrite:
            return

        sld = self.publishStyle(layer, overwrite,
                                name) if style is None else None

        layer = self.preprocess(layer)
        self.upload(layer, workspace, overwrite, name)

        if sld is not None or style is not None:
            #assign style to created store
            publishing = self.catalog.get_layer(name)
            publishing.default_style = style or self.catalog.get_style(name)
            self.catalog.save(publishing)
Exemplo 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)
Exemplo n.º 5
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
Exemplo 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
Exemplo n.º 7
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)
Exemplo n.º 8
0
    def publishLayer (self, layer, workspace=None, overwrite=True, name=None, style=None):
        '''
        Publishes a QGIS layer.
        It creates the corresponding store and the layer itself.

        layer: the layer to publish, whether as a QgsMapLayer object or its name in the QGIS TOC.

        workspace: the workspace to publish to. USes the default workspace if not passed
        or None

        name: the name for the published layer. Uses the QGIS layer name if not passed
        or None

        style: the style to use from the ones in the catalog. Will upload the QGIS style if
        not passed or None

        '''

        if isinstance(layer, str):
            layer = layers.resolveLayer(layer)

        addTrackedLayer(layer, self.catalog.service_url)

        name = xmlNameFixUp(name) if name is not None \
            else xmlNameFixUp(layer.name())

        gslayer = self.catalog.get_layer(name)
        if gslayer is not None and not overwrite:
            return

        sld = self.publishStyle(layer, overwrite, name) if style is None else None

        self.upload(layer, workspace, overwrite, name)

        if sld is not None or style is not None:
            #assign style to created store
            publishing = self.catalog.get_layer(name)
            publishing.default_style = style or self.catalog.get_styles(name)[0]
            self.catalog.save(publishing)
Exemplo n.º 9
0
    def publishLayer(self, layer, workspace=None, overwrite=True, name=None, style=None):
        """
        Publishes a QGIS layer.
        It creates the corresponding store and the layer itself.
        If a pre-upload hook is set, its runs it and publishes the resulting layer

        layer: the layer to publish, whether as a QgsMapLayer object or its name in the QGIS TOC.

        workspace: the workspace to publish to. USes the default workspace if not passed
        or None

        name: the name for the published layer. Uses the QGIS layer name if not passed
        or None

        style: the style to use from the ones in the catalog. Will upload the QGIS style if
        not passed or None

        """

        if isinstance(layer, basestring):
            layer = layers.resolveLayer(layer)

        name = xmlNameFixUp(name) if name is not None else xmlNameFixUp(layer.name())

        gslayer = self.catalog.get_layer(name)
        if gslayer is not None and not overwrite:
            return

        sld = self.publishStyle(layer, overwrite, name) if style is None else None

        layer = self.preprocess(layer)
        self.upload(layer, workspace, overwrite, name)

        if sld is not None or style is not None:
            # assign style to created store
            publishing = self.catalog.get_layer(name)
            publishing.default_style = style or self.catalog.get_style(name)
            self.catalog.save(publishing)
Exemplo n.º 10
0
 def __init__(self, kind, **kwargs):
     unique = kwargs.get('unique', False)
     super(GSXmlNameDialog, self).__init__(
         boxtitle='GeoServer {0} name'.format(kind),
         boxmsg='Define unique {0}'.format(kind) +
                ' or overwrite existing' if not unique else '',
         name=xmlNameFixUp(kwargs.get('name', '')),
         namemsg=kwargs.get('namemsg', ''),
         nameregex=kwargs.get('nameregex', xmlNameRegex()),
         nameregexmsg=kwargs.get('nameregexmsg', xmlNameRegexMsg()),
         names=kwargs.get('names', None),
         unique=unique,
         maxlength=kwargs.get('maxlength', 0),
         parent=kwargs.get('parent', None))
Exemplo n.º 11
0
 def __init__(self, kind, **kwargs):
     unique = kwargs.get('unique', False)
     super(GSXmlNameDialog, self).__init__(
         boxtitle='GeoServer {0} name'.format(kind),
         boxmsg='Define unique {0}'.format(kind) +
                ' or overwrite existing' if not unique else '',
         name=xmlNameFixUp(kwargs.get('name', '')),
         namemsg=kwargs.get('namemsg', ''),
         nameregex=kwargs.get('nameregex', xmlNameRegex()),
         nameregexmsg=kwargs.get('nameregexmsg', xmlNameRegexMsg()),
         names=kwargs.get('names', None),
         unique=unique,
         maxlength=kwargs.get('maxlength', 0),
         parent=kwargs.get('parent', None))
Exemplo n.º 12
0
    def testGSNameDialog(self):
        ndlg = GSNameDialog(
            boxtitle='GeoServer data store name',
            boxmsg='My groupbox message',
            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=True,
            maxlength=10)

        # maxlength > 10
        self.assertFalse(ndlg.okButton.isEnabled())
        self.assertIsNone(ndlg.definedName())
        self.assertFalse(ndlg.overwritingName())

        # maxlength = 10
        ndlg.nameBox.setName('my_pg_conn')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertEqual(ndlg.definedName(), 'my_pg_conn')
        self.assertFalse(ndlg.overwritingName())

        # unique = True
        ndlg.nameBox.setName('name_one')
        self.assertIsNone(ndlg.definedName())
        self.assertFalse(ndlg.okButton.isEnabled())
        self.assertFalse(ndlg.overwritingName())

        del ndlg
        # unique=False
        ndlg = GSNameDialog(
            boxtitle='GeoServer data store name',
            boxmsg='My groupbox message',
            name='name',
            names=['name_one', 'name_two', 'name_three'],
            unique=False)

        # not overwriting
        self.assertEqual(ndlg.definedName(), 'name')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertFalse(ndlg.overwritingName())
        # overwriting
        ndlg.nameBox.setName('name_one')
        self.assertEqual(ndlg.definedName(), 'name_one')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertTrue(ndlg.overwritingName())
Exemplo n.º 13
0
    def testGSNameDialog(self):
        ndlg = GSNameDialog(
            boxtitle='GeoServer data store name',
            boxmsg='My groupbox message',
            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=True,
            maxlength=10)

        # maxlength > 10
        self.assertFalse(ndlg.okButton.isEnabled())
        self.assertIsNone(ndlg.definedName())
        self.assertFalse(ndlg.overwritingName())

        # maxlength = 10
        ndlg.nameBox.setName('my_pg_conn')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertEqual(ndlg.definedName(), 'my_pg_conn')
        self.assertFalse(ndlg.overwritingName())

        # unique = True
        ndlg.nameBox.setName('name_one')
        self.assertIsNone(ndlg.definedName())
        self.assertFalse(ndlg.okButton.isEnabled())
        self.assertFalse(ndlg.overwritingName())

        del ndlg
        # unique=False
        ndlg = GSNameDialog(
            boxtitle='GeoServer data store name',
            boxmsg='My groupbox message',
            name='name',
            names=['name_one', 'name_two', 'name_three'],
            unique=False)

        # not overwriting
        self.assertEqual(ndlg.definedName(), 'name')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertFalse(ndlg.overwritingName())
        # overwriting
        ndlg.nameBox.setName('name_one')
        self.assertEqual(ndlg.definedName(), 'name_one')
        self.assertTrue(ndlg.okButton.isEnabled())
        self.assertTrue(ndlg.overwritingName())
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def updateNameBox(self, name):
     self.nameBox.setName(xmlNameFixUp(name))
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def _publishPostgisLayer(self,
                             layer,
                             workspace,
                             overwrite,
                             name,
                             storename=None):
        uri = QgsDataSourceURI(layer.dataProvider().dataSourceUri())

        # check for table.name conflict in existing layer names where the
        # table.name is not the same as the user-chosen layer name,
        # i.e. unintended overwrite
        resource = self.catalog.get_resource(uri.table())
        if resource is not None and uri.table() != name:
            raise Exception(
                "QGIS PostGIS layer has table name conflict with "
                "existing GeoServer layer name: {0}\n"
                "You may need to rename GeoServer layer name.".format(
                    uri.table()))

        conname = self.getConnectionNameFromLayer(layer)
        storename = xmlNameFixUp(storename or conname)

        if not xmlNameIsValid(storename):
            raise Exception("Database connection name is invalid XML and can "
                            "not be auto-fixed: {0} -> {1}".format(
                                conname, storename))

        connInfo = uri.connectionInfo()
        (success, user,
         passwd) = QgsCredentials.instance().get(connInfo, None, None)
        if success:
            QgsCredentials.instance().put(connInfo, user, passwd)
        else:
            raise Exception("Couldn't connect to database")

        store = createPGFeatureStore(self.catalog,
                                     storename,
                                     workspace=workspace,
                                     overwrite=overwrite,
                                     host=uri.host(),
                                     database=uri.database(),
                                     schema=uri.schema(),
                                     port=uri.port(),
                                     user=user,
                                     passwd=passwd)
        if store is not None:
            rscname = name if uri.table() != name else uri.table()
            grpswlyr = []
            if overwrite:
                # TODO: How do we honor *unchecked* user setting of
                #   "Delete resource when deleting layer" here?
                #   Is it an issue, if overwrite is expected?

                # We will soon have two layers with slightly different names,
                # a temp based upon table.name, the other possibly existing
                # layer with the same custom name, which may belong to group(s).
                # If so, remove existing layer from any layer group, before
                # continuing on with layer delete and renaming of new feature
                # type layer to custom name, then add new resultant layer back
                # to any layer groups the existing layer belonged to. Phew!

                flyr = self.catalog.get_layer(rscname)
                if flyr is not None:
                    grpswlyr = groupsWithLayer(self.catalog, flyr)
                    if grpswlyr:
                        removeLayerFromGroups(self.catalog, flyr, grpswlyr)
                    self.catalog.delete(flyr)
                # TODO: What about when the layer name is the same, but the
                #   underlying db connection/store has changed? Not an issue?
                #   The layer is deleted, which is correct, but the original
                #   db store and feature type will not be changed. A conflict?
                frsc = store.get_resources(name=rscname)
                if frsc is not None:
                    self.catalog.delete(frsc)

            # for dbs the name has to be the table name, initially
            ftype = self.catalog.publish_featuretype(uri.table(), store,
                                                     layer.crs().authid())

            # once table-based feature type created, switch name to user-chosen
            if ftype.name != rscname:
                ftype.dirty["name"] = rscname
            self.catalog.save(ftype)

            # now re-add to any previously assigned-to layer groups
            if overwrite and grpswlyr:
                ftype = self.catalog.get_resource(rscname)
                if ftype:
                    addLayerToGroups(self.catalog,
                                     ftype,
                                     grpswlyr,
                                     workspace=workspace)
Exemplo n.º 20
0
 def updateNameBox(self, name):
     self.nameBox.setName(xmlNameFixUp(name))
Exemplo n.º 21
0
    def _publishPostgisLayer(self, layer, workspace, overwrite, name, storename=None):
        uri = QgsDataSourceURI(layer.dataProvider().dataSourceUri())



        conname = self.getConnectionNameFromLayer(layer)
        storename = xmlNameFixUp(storename or conname)

        if not xmlNameIsValid(storename):
            raise Exception("Database connection name is invalid XML and can "
                            "not be auto-fixed: {0} -> {1}"
                            .format(conname, storename))


        user = uri.username()
        passwd = uri.password()
        if not uri or not passwd:
            connInfo = uri.connectionInfo()
            (success, user, passwd) = QgsCredentials.instance().get(connInfo, None, None)
            if success:
                QgsCredentials.instance().put(connInfo, user, passwd)
            else:
                raise Exception("Couldn't connect to database")

        store = createPGFeatureStore(self.catalog,
                                     storename,
                                     workspace = workspace,
                                     overwrite = overwrite,
                                     host = uri.host(),
                                     database = uri.database(),
                                     schema = uri.schema(),
                                     port = uri.port(),
                                     user = user,
                                     passwd = passwd)
        if store is not None:
            grpswlyr = []
            if overwrite:
                # TODO: How do we honor *unchecked* user setting of
                #   "Delete resource when deleting layer" here?
                #   Is it an issue, if overwrite is expected?

                # We will soon have two layers with slightly different names,
                # a temp based upon table.name, the other possibly existing
                # layer with the same custom name, which may belong to group(s).
                # If so, remove existing layer from any layer group, before
                # continuing on with layer delete and renaming of new feature
                # type layer to custom name, then add new resultant layer back
                # to any layer groups the existing layer belonged to. Phew!

                flyr = self.catalog.get_layer(name)
                if flyr is not None:
                    grpswlyr = groupsWithLayer(self.catalog, flyr)
                    if grpswlyr:
                        removeLayerFromGroups(self.catalog, flyr, grpswlyr)
                    self.catalog.delete(flyr)
                # TODO: What about when the layer name is the same, but the
                #   underlying db connection/store has changed? Not an issue?
                #   The layer is deleted, which is correct, but the original
                #   db store and feature type will not be changed. A conflict?
                frsc = store.get_resources(name=name)
                if frsc is not None:
                    self.catalog.delete(frsc)

            # for dbs the name has to be the table name, initially
            ftype = self.catalog.publish_featuretype(uri.table(), store,
                                                     layer.crs().authid())

            # once table-based feature type created, switch name to user-chosen
            if ftype.name != name:
                ftype.dirty["name"] = name
                ftype.dirty["title"] = name
            self.catalog.save(ftype)

            # now re-add to any previously assigned-to layer groups
            if overwrite and grpswlyr:
                ftype = self.catalog.get_resource(name)
                if ftype:
                    addLayerToGroups(self.catalog, ftype, grpswlyr,
                                     workspace=workspace)