def test_login(self):
     """Test we can click OK."""
     login = Login(self.url, self.username, self.password)
     # Wait until it finished
     while not login.is_finished():
         QCoreApplication.processEvents()
     self.assertIsNotNone(login.get_json_results())
Example #2
0
    def set_progress_bar(self, value):
        """Set progress bar value.

        :param value: integer value for progress bar
        :type value: int
        """
        self.progress_bar.setValue(value)
        QCoreApplication.processEvents()
Example #3
0
    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface 
        """

        # Save reference to the QGIS interface
        self.iface = iface

        self.canvas = iface.mapCanvas()

        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir, 'i18n',
            'Map_Corners_Coordinates_{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create the QDockWidget (after translation) and keep reference
        self.dlg = MapCornersCoordinatesDialog(self.iface.mainWindow())

        # Declare instance attributes
        self.actions = []
        self.menu = self.tr(u'&Map Corners Coordinates')
        # TODO: We are going to let the user set this up in a future iteration
        self.toolbar = self.iface.addToolBar(
            self.tr(u'Map Corners Coordinates'))
        self.toolbar.setObjectName('MapCornersCoordinates')

        # Disable saveButton since there is no file chosen (method dirButton)
        self.dlg.saveButton.setEnabled(False)

        self.dlg.captureButton.clicked.connect(self.readCoor)
        self.dlg.saveButton.clicked.connect(self.saveCoor)

        # Update system_Box on map crs changed
        try:
            self.iface.mapCanvas().destinationCrsChanged.connect(
                self.updateCrs)
        except:
            self.iface.mapCanvas().mapRenderer().destinationSrsChanged.connect(
                self.updateCrs)

        # add plugin icon into plugin toolbar
        self.toolButton = QToolButton()
        self.iface.addToolBarWidget(self.toolButton)
        self.dlg.dir_toolbutton.clicked.connect(self.dirButton)
    def organization_projects_spatial_call_finished(self, result):
        """Function when Organization Project Spatial Api finished.

        :param result: result of request
        :type result: (bool, list/dict/str)
        """
        self.save_organizations()
        if result[0]:
            # save result to local file
            organization_slug = result[2]
            project_slug = result[3]
            vlayers = Utilities.save_layer(result[1], organization_slug,
                                           project_slug)
            self.progress_bar.setValue(50)

            download_relationship_and_party = False

            if self.project['access'] == 'public':
                # Get organization
                status, results = self.organisation_api.summary_organization(
                    organization_slug)

                if status and 'users' in results:
                    for user in results['users']:
                        if user['username'] == get_setting('username'):
                            download_relationship_and_party = True
                            break
            else:
                download_relationship_and_party = True

            relationship_layer_id = None
            party_layer_id = None

            if download_relationship_and_party:
                relationship_layer = self.relationships_layer(vlayers)
                if relationship_layer:
                    relationship_layer_id = relationship_layer.id()

                party_layer = self.parties_layer()
                if party_layer:
                    party_layer_id = party_layer.id()

            self.progress_bar.setValue(80)

            QCoreApplication.processEvents()
            Utilities.save_project_basic_information(self.project, vlayers,
                                                     relationship_layer_id,
                                                     party_layer_id)
        else:
            pass
        self.progress_bar.setValue(self.progress_bar.maximum())
        self.warning_label.setText(self.loaded_label_string)
        self.parent.close()
    def __init__(self, iface):
        QgsDockWidget.__init__(
            self,
            QCoreApplication.translate('AttributesDock', 'Quick Attribution'))
        self.iface = iface
        self.widget = QWidget()
        self.widget.setLayout(QGridLayout())
        self.widget.setContentsMargins(0, 0, 0, 0)
        self.layerComboBox = QgsMapLayerComboBox()
        self.layerComboBox.layerChanged.connect(self.setLayer)
        self.layerComboBox.setSizePolicy(QSizePolicy.Expanding,
                                         QSizePolicy.Fixed)
        self.layerTitleLabel = QLabel()
        self.widget.layout().addWidget(self.layerTitleLabel, 0, 0, 1, 1)
        self.widget.layout().addWidget(self.layerComboBox, 0, 1, 1, 1)
        self.formWidget = QWidget()
        self.formWidget.setLayout(QGridLayout())
        self.formWidget.setContentsMargins(0, 0, 0, 0)
        self.widget.layout().addWidget(self.formWidget, 1, 0, 1, 2)
        self.setWidget(self.widget)
        self.attributeForm = None
        self.layer = None
        self.feature = None

        self.layerComboBox.setFilters(QgsMapLayerProxyModel.WritableLayer
                                      | QgsMapLayerProxyModel.VectorLayer)

        QgsProject.instance().readProject.connect(self.onProjectRead)
Example #6
0
 def tr(self, message):
     """Get the translation for a string using Qt translation API.
     
     We implement this ourselves since we do not inherit QObject.
     
     :param message: String for translation.
     :type message: str, QString
     
     :returns: Translated version of message.
     :rtype: QString
     """
     # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
     return QCoreApplication.translate('Map_Corners_Coordinates', message)
Example #7
0
    def organization_projects_spatial_call_finished(self, result):
        """Function when Organization Project Spatial Api finished.

        :param result: result of request
        :type result: (bool, list/dict/str)
        """
        if result[0]:
            # save result to local file
            organization_slug = result[2]
            project_slug = result[3]
            vlayers = Utilities.save_layer(result[1], organization_slug,
                                           project_slug)
            relationship_layer = self.relationships_layer(
                vlayers, organization_slug, project_slug)
            party_layer = self.parties_layer(organization_slug, project_slug)
            QCoreApplication.processEvents()
            Utilities.save_project_basic_information(
                information=self.project_upload_result,
                vlayers=vlayers,
                relationship_layer_id=relationship_layer.id(),
                party_layer_id=party_layer.id())
        else:
            pass
    def parties_layer(self):
        """Create parties layer.

        :param vector_layer: QGS vector layer in memory
        :type vector_layer: QgsVectorLayer
        """

        organization_slug = self.project['organization']['slug']
        project_slug = self.project['slug']
        attribute = 'parties'

        csv_path = get_csv_path(organization_slug, project_slug, attribute)

        if os.path.isfile(csv_path):
            os.remove(csv_path)

        api = u'/api/v1/organizations/{organization_slug}/projects/' \
              u'{project_slug}/parties/'.format(
                organization_slug=organization_slug,
                project_slug=project_slug)

        connector = ApiConnect(get_url_instance() + api)
        status, results = connector.get(paginated=True)

        if not status:
            return

        party_layer = tools.create_memory_layer(
            layer_name='%s/%s/%s' %
            (organization_slug, project_slug, attribute),
            geometry=QGis.NoGeometry,
            fields=[
                QgsField('id', QVariant.String, "string"),
                QgsField('name', QVariant.String, "string"),
                QgsField('type', QVariant.String, "string"),
                QgsField('attributes', QVariant.String, "string"),
            ])

        QgsMapLayerRegistry.instance().addMapLayer(party_layer)

        for party in results:
            party_layer.startEditing()
            feature = QgsFeature()
            questionnaire_attr = party['attributes']
            if not questionnaire_attr:
                questionnaire_attr = '-'
            else:
                questionnaire_attr = json.dumps(questionnaire_attr)
            feature.setAttributes([
                party['id'], party['name'], party['type'], questionnaire_attr
            ])
            party_layer.addFeature(feature, True)
            party_layer.commitChanges()
            QCoreApplication.processEvents()

        self.process_attributes(party_layer)

        Utilities.add_tabular_layer(party_layer, organization_slug,
                                    project_slug, attribute)

        return party_layer
Example #9
0
 def connections(self):
     return [
         VLayerDBPlugin(
             QCoreApplication.translate('db_manager', 'QGIS layers'))
     ]
Example #10
0
 def typeNameString(self):
     return QCoreApplication.translate('db_manager', 'Virtual Layers')
Example #11
0
 def connections(self):
     return [VLayerDBPlugin(QCoreApplication.translate('db_manager', 'QGIS layers'))]
Example #12
0
 def typeNameString(self):
     return QCoreApplication.translate('db_manager', 'Virtual Layers')