I have a very simple file where I have a Qcombobox Filter. When you select the filter, I run through a case on the index and output results.
So, on selection I trigger:
self.comboBox.activated.connect(self.handleActivated)
Then,
my handled function is
def handleActivated(self, index):
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName("data.db")
db.open()
# tableView = QtWidgets.QTableView()
if index == 0:
sourceModel = QSqlQueryModel()
sourceModel.setQuery(
"SELECT url,size,content_type FROM 'google.com.au'",
db)
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(sourceModel)
self.tableView.setModel(proxyModel)
self.tableView.setSortingEnabled(True)
elif index == 1:
sourceModel = QSqlQueryModel()
sourceModel.setQuery(
"SELECT url,size,content_type FROM 'google.com.au' WHERE content_type LIKE '%html%'",
db)
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(sourceModel)
self.tableView.setModel(proxyModel)
self.tableView.setSortingEnabled(True)
elif index == 2:
sourceModel = QSqlQueryModel()
sourceModel.setQuery(
"SELECT url,size,content_type FROM 'google.com.au' WHERE content_type LIKE '%javascript%'",
db)
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(sourceModel)
self.tableView.setModel(proxyModel)
self.tableView.setSortingEnabled(True)
My question is, is this the most efficient way of writing this code ? I have upto 15 filters and this will become really cumbersome in my main file.