def map_load(self,  item=None,  row=None):     
     self.ui.widgetServices.close()
     self.setCursor(Qt.WaitCursor)
     map_id = self.ui.tabMaps.currentItem().data(Qt.UserRole)
     map_name = self.ui.tabMaps.currentItem().text()
     result = self.api.load_map_project(map_name,  map_id)
     qgs_file_name = '%s/%s.qgs' % (tempfile.gettempdir(), map_name)
     qgs_file = open(qgs_file_name,  'w')
     qgs_file.write(result)
     qgs_file.close()
     project = QgsProject.instance()
     if project.isDirty():
         ok = QMessageBox.information(
             self,
             self.tr("Save Project"),
             self.tr("""Your actual project has changes. Do you want to save the project?"""),
             QMessageBox.StandardButtons(
                 QMessageBox.Abort |
                 QMessageBox.Discard |
                 QMessageBox.Save))
         if ok:
             project.write()           
             
     project.read(qgs_file_name)
     project.setDirty(False)
     self.iface.mainWindow().setWindowTitle("QGIS %s - %s" % (Qgis.QGIS_VERSION,  map_name))
     self.unsetCursor()
Exemplo n.º 2
0
 def setLayer(self, layer):
     self.model.setLayer(layer)
     if self.model.rowCount() == 0:
         self.on_resetButton_clicked()
     else:
         dlg = QMessageBox(self)
         dlg.setText("Do you want to reset the field mapping?")
         dlg.setStandardButtons(
             QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No))
         dlg.setDefaultButton(QMessageBox.No)
         if dlg.exec_() == QMessageBox.Yes:
             self.on_resetButton_clicked()
Exemplo n.º 3
0
 def setLayer(self, layer):
     if layer is None or self.layer == layer:
         return
     self.layer = layer
     if self.model.rowCount(QModelIndex()) == 0:
         self.on_resetButton_clicked()
         return
     dlg = QMessageBox(self)
     dlg.setText(self.tr("Do you want to reset the field mapping?"))
     dlg.setStandardButtons(
         QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No))
     dlg.setDefaultButton(QMessageBox.No)
     if dlg.exec_() == QMessageBox.Yes:
         self.on_resetButton_clicked()
Exemplo n.º 4
0
    def delete_database(self):
        name = self.ui.tabDatabases.currentItem().text()

        answer = False

        for layer in list(self.PROJECT_INSTANCE.mapLayers().values()):
            if QgsDataSourceUri(layer.publicSource()).database() == name:

                if not answer:
                    answer = QMessageBox.question(
                        self, self.tr("Warning"),
                        self.
                        tr('You have layers from database "{name}" loaded in your project! Do you want to remove them before you delete database "{name}"?'
                           ).format(name=name),
                        QMessageBox.StandardButtons(QMessageBox.Cancel
                                                    | QMessageBox.Yes))

                if answer == QMessageBox.Yes:
                    self.PROJECT_INSTANCE.removeMapLayer(layer.id())

        if answer == QMessageBox.Cancel:
            QMessageBox.warning(
                None, self.tr('Warning'),
                self.tr('Deletion of database "{name}" interrupted!').format(
                    name=name))
            return

        msgBox = QMessageBox()
        msgBox.setWindowTitle(self.tr("Delete QGIS Cloud database."))
        msgBox.setText(
            self.tr("Do you want to delete the database \"%s\"?") % name)
        msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        msgBox.setDefaultButton(QMessageBox.Cancel)
        msgBox.setIcon(QMessageBox.Question)
        ret = msgBox.exec_()

        if ret == QMessageBox.Ok:
            self.setCursor(Qt.WaitCursor)
            result = self.api.delete_database(name)
            self.show_api_error(result)
            self.ui.btnDbDelete.setEnabled(False)
            time.sleep(2)
            self.refresh_databases()
            self.unsetCursor()
    def check_login(self):
        version_ok = True
        if not self.api.check_auth():
#            res = QMessageBox.information(
#                self,
#                self.tr("QGIS 3 message"),
#                self.tr("""You have started the QGIS Cloud Plugin with QGIS 3. This configuration is not stable and is not intended for productive use. A lot can still change in QGIS before the first QGIS 3 LTR. Therefore, it is possible that the plugin does not work as you expect or terminates with errors. If you need a stable version of QGIS Cloud, please continue working with QGIS 2."""),
#                QMessageBox.StandardButtons(
#                QMessageBox.Close))        	
            login_dialog = QDialog(self)
            login_dialog.ui = Ui_LoginDialog()
            login_dialog.ui.setupUi(login_dialog)
            login_dialog.ui.editUser.setText(self.user)
            login_ok = False
            while not login_ok and version_ok:
                self.api.set_url(self.api_url())
                if not login_dialog.exec_():
                    self.api.set_auth(
                        user=login_dialog.ui.editUser.text(), password=None)
                    return login_ok
                self.api.set_auth(
                    user=login_dialog.ui.editUser.text(),
                    password=login_dialog.ui.editPassword.text())
                try:
                    login_info = self.api.check_login(
                        version_info=self._version_info())

# QGIS private Cloud has no tos_accepted
                    try:
                        if not login_info['tos_accepted']:
                            result = QMessageBox.information(
                                None,
                                self.tr("Accept new Privacy Policy"),
                                self.tr("""Due to the GDPR qgiscloud.com has a new <a href='http://qgiscloud.com/en/pages/privacy'> Privacy Policy </a>. 
                                To continue using qgiscloud.com, you must accept the new policy. """),
                                QMessageBox.StandardButtons(
                                    QMessageBox.No |
                                    QMessageBox.Yes))
                            
                            if result == QMessageBox.No:
                                login_ok = False
                                return
                            else:
                                result = self.api.accept_tos()
                    except:
                        pass
                            
                    self.user = login_dialog.ui.editUser.text()
                    self._update_clouddb_mode(login_info['clouddb'])
                    version_ok = StrictVersion(self.version) >= StrictVersion(login_info['current_plugin'])
                    if not version_ok:
                        self.ui.lblVersionPlugin.setPalette(self.palette_red)
                        QMessageBox.information(None, self.tr('New Version'),  self.tr('New plugin release {version} is available! Please upgrade the QGIS Cloud plugin.').format(version=login_info['current_plugin']))
                    self.store_settings()
                    self.ui.btnLogin.hide()
                    self.ui.lblSignup.hide()
                    self.ui.btnLogout.show()
                    self.ui.widgetDatabases.setEnabled(True)
                    self.ui.widgetMaps.setEnabled(True)

                    self.ui.lblLoginStatus.setText(
                        self.tr("Logged in as {0} ({1})").format(self.user, login_info['plan']))
                    self.ui.lblLoginStatus.show()
                    self._push_message(
                        self.tr("QGIS Cloud"),
                        self.tr("Logged in as {0}").format(self.user),
                        level=0, duration=2)
                    self.refresh_databases()
                    self.refresh_maps()
                    if not version_ok:
                        self._push_message(self.tr("QGIS Cloud"), self.tr(
                            "Unsupported versions detected. Please check your versions first!"), level=1)
                        version_ok = False
                        self.ui.tabWidget.setCurrentWidget(self.ui.aboutTab)
                    login_ok = True
                    self.update_local_layers()
            
                except ForbiddenError:
                    QMessageBox.critical(
                        self, self.tr("Account Disabled"),
                        self.tr("Account {username} is disabled! Please contact [email protected]").format(username=login_dialog.ui.editUser.text()))
                    login_ok = False                    
                except UnauthorizedError:
                    QMessageBox.critical(
                        self, self.tr("Login for user {username} failed").format(username=login_dialog.ui.editUser.text()),
                        self.tr("Wrong user name or password"))
                    login_ok = False
                except (TokenRequiredError, ConnectionException) as e:
                    QMessageBox.critical(
                        self, self.tr("Login failed"),
                        self.tr("Login failed: %s") % str(e))
                    login_ok = False
        return version_ok