Пример #1
0
    def addCarhabLayer(self, carhabLayer):
        db = DbManager(carhabLayer.dbPath)
        if not db.version() == last_db_version():
            versions = [os.path.basename(os.path.join(pluginDirectory,'update', f)).split('upd_')[1].split('.sql')[0] for f in listdir(os.path.join(pluginDirectory,'update')) if os.path.basename(os.path.join(pluginDirectory,'update', f)).startswith('upd_')]
            versions = [v for v in versions if v > db.version()]
            versions.sort()
            for v in versions:
                res = db.executeScript(os.path.join(pluginDirectory,'update', 'upd_'+v+'.sql'))
                if res:
                    error_update_db()
                else:
                    db.set_version(last_db_version())
                    db.commit()
        self.layerMap[carhabLayer.id] = carhabLayer

        root = QgsProject.instance().layerTreeRoot()
        group = root.addGroup('carhab_'+carhabLayer.getName())

        for tableToLoad in ('point', 'polyline', 'polygon'):
            group.addLayer(self.loadLayerTable(carhabLayer, tableToLoad))
            #self.loadLayerTable(carhabLayer.dbPath, tableToLoad)

        # Create row corresponding to carhab layer into carhab layer list.
        uiPath = os.path.join(pluginDirectory, 'carhab_layer_item.ui')
        carhabLayerWdgt = loadUi(uiPath)

        jobNameLbl = carhabLayerWdgt.findChild(QLabel,'job_name_label')
        jobNameLbl.setText(carhabLayer.getName())
Пример #2
0
def last_db_version():
    db = DbManager(path.join(pluginDirectory, 'empty.sqlite'))
    return db.version()