Skip to content
Permalink
Browse files

Add async model for gpkg

  • Loading branch information
pblottiere committed Mar 2, 2018
1 parent f5a3e60 commit cf53a4cb14d97f432ab4e5febde8513b380858bc
@@ -165,6 +165,10 @@ def _commit(self):
self._rollback()
raise DbError(e)

def cancel(self):
if self.connection:
self.connection.interrupt()

@classmethod
def isValidDatabase(cls, path):
if hasattr(gdal, 'OpenEx'):
@@ -20,7 +20,13 @@
***************************************************************************/
"""

from ..data_model import TableDataModel, SqlResultModel
from qgis.core import QgsMessageLog

from ..data_model import (TableDataModel,
SqlResultModel,
SqlResultModelAsync,
SqlResultModelTask)
from ..plugin import BaseError


class GPKGTableDataModel(TableDataModel):
@@ -47,5 +53,34 @@ def rowCount(self, index=None):
return self.fetchedCount


class GPKGSqlResultModelTask(SqlResultModelTask):

def __init__(self, db, sql, parent):
SqlResultModelTask.__init__(self, db, sql, parent)

def run(self):
try:
self.model = GPKGSqlResultModel(self.db, self.sql, None)
except BaseError as e:
self.error = e
QgsMessageLog.logMessage(e.msg)
return False
return True

def cancel(self):
self.db.connector.cancel()
SqlResultModelTask.cancel(self)


class GPKGSqlResultModelAsync(SqlResultModelAsync):

def __init__(self, db, sql, parent):
SqlResultModelAsync.__init__(self)

self.task = GPKGSqlResultModelTask(db, sql, parent)
self.task.taskCompleted.connect(self.modelDone)
self.task.taskTerminated.connect(self.modelDone)


class GPKGSqlResultModel(SqlResultModel):
pass
@@ -132,6 +132,11 @@ def sqlResultModel(self, sql, parent):

return GPKGSqlResultModel(self, sql, parent)

def sqlResultModelAsync(self, sql, parent):
from .data_model import GPKGSqlResultModelAsync

return GPKGSqlResultModelAsync(self, sql, parent)

def registerDatabaseActions(self, mainWindow):
action = QAction(self.tr("Run &Vacuum"), self)
mainWindow.registerAction(action, self.tr("&Database"), self.runVacuumActionSlot)

0 comments on commit cf53a4c

Please sign in to comment.
You can’t perform that action at this time.