def test_link_feature(self):
        """
        Check if an existing feature can be linked
        """
        wrapper = self.createWrapper(self.vl_a, '"name"=\'Douglas Adams\'')

        f = QgsFeature(self.vl_b.fields())
        f.setAttributes([self.vl_b.dataProvider().defaultValue(0), 'The Hitchhiker\'s Guide to the Galaxy'])
        self.vl_b.addFeature(f)

        def choose_linked_feature():
            dlg = QApplication.activeModalWidget()
            dlg.setSelectedFeatures([f.id()])
            dlg.accept()

        btn = self.widget.findChild(QToolButton, 'mLinkFeatureButton')

        timer = QTimer()
        timer.setSingleShot(True)
        timer.setInterval(0) # will run in the event loop as soon as it's processed when the dialog is opened
        timer.timeout.connect(choose_linked_feature)
        timer.start()

        btn.click()
        # magically the above code selects the feature here...

        link_feature = self.vl_link.getFeatures(QgsFeatureRequest().setFilterExpression('"fk_book"={}'.format(f[0]))).next()
        self.assertIsNotNone(link_feature[0])

        self.assertEquals(self.table_view.model().rowCount(), 1)
    def test_link_feature(self):
        """
        Check if an existing feature can be linked
        """
        wrapper = self.createWrapper(self.vl_a, '"name"=\'Douglas Adams\'')  # NOQA

        f = QgsFeature(self.vl_b.fields())
        f.setAttributes([self.vl_b.dataProvider().defaultValue(0), 'The Hitchhiker\'s Guide to the Galaxy'])
        self.vl_b.addFeature(f)

        def choose_linked_feature():
            dlg = QApplication.activeModalWidget()
            dlg.setSelectedFeatures([f.id()])
            dlg.accept()

        btn = self.widget.findChild(QToolButton, 'mLinkFeatureButton')

        timer = QTimer()
        timer.setSingleShot(True)
        timer.setInterval(0)  # will run in the event loop as soon as it's processed when the dialog is opened
        timer.timeout.connect(choose_linked_feature)
        timer.start()

        btn.click()
        # magically the above code selects the feature here...

        link_feature = self.vl_link.getFeatures(QgsFeatureRequest().setFilterExpression('"fk_book"={}'.format(f[0]))).next()
        self.assertIsNotNone(link_feature[0])

        self.assertEquals(self.table_view.model().rowCount(), 1)
Example #3
0
    def loadPreview(self, item):
        if item == self.item and not self.dirty:
            return

        if item is None:
            return

        self._clear()

        if isinstance(item, Table) and item.type in [Table.VectorType, Table.RasterType]:
            # update the preview, but first let the manager chance to show the canvas
            def runPrev():
                return self._loadTablePreview(item)
            QTimer.singleShot(50, runPrev)
        else:
            return

        self.item = item
        self.item.aboutToChange.connect(self.setDirty)
Example #4
0
def show_console():
    """ called from QGIS to open the console """
    global _console
    if _console is None:
        parent = iface.mainWindow() if iface else None
        _console = PythonConsole(parent)
        _console.show()  # force show even if it was restored as hidden
        # set focus to the console so the user can start typing
        # defer the set focus event so it works also whether the console not visible yet
        QTimer.singleShot(0, _console.activate)
    else:
        _console.setVisible(not _console.isVisible())
        # set focus to the console so the user can start typing
        if _console.isVisible():
            _console.activate()
    ## Shows help on first launch of the console
    settings = QSettings()
    if settings.value('pythonConsole/contextHelpOnFirstLaunch', True, type=bool):
        QgsContextHelp.run("PythonConsole")
        settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False)
Example #5
0
    def loadPreview(self, item):
        if item == self.item and not self.dirty:
            return

        if item is None:
            return

        self._clear()

        if isinstance(item, Table) and item.type in [
                Table.VectorType, Table.RasterType
        ]:
            # update the preview, but first let the manager chance to show the canvas
            def runPrev():
                return self._loadTablePreview(item)

            QTimer.singleShot(50, runPrev)
        else:
            return

        self.item = item
        self.item.aboutToChange.connect(self.setDirty)
Example #6
0
def show_console():
    """ called from QGIS to open the console """
    global _console
    if _console is None:
        parent = iface.mainWindow() if iface else None
        _console = PythonConsole(parent)
        _console.show()  # force show even if it was restored as hidden
        # set focus to the console so the user can start typing
        # defer the set focus event so it works also whether the console not visible yet
        QTimer.singleShot(0, _console.activate)
    else:
        _console.setVisible(not _console.isVisible())
        # set focus to the console so the user can start typing
        if _console.isVisible():
            _console.activate()
    ## Shows help on first launch of the console
    settings = QSettings()
    if settings.value('pythonConsole/contextHelpOnFirstLaunch',
                      True,
                      type=bool):
        QgsContextHelp.run("PythonConsole")
        settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False)