Clean up code

Just some simplifications, nothing more.
This commit is contained in:
Martin Kleusberg
2016-08-16 22:45:22 +02:00
parent 0dab0a28a1
commit d288a41dba
2 changed files with 31 additions and 21 deletions

View File

@@ -293,7 +293,7 @@ bool MainWindow::fileOpen(const QString& fileName, bool dontAddToRecentFiles)
loadExtensionsFromSettings(); loadExtensionsFromSettings();
populateStructure(); populateStructure();
if(ui->mainTab->currentIndex() == 1) if(ui->mainTab->currentIndex() == 1)
populateTable(ui->comboBrowseTable->currentText()); populateTable();
else if(ui->mainTab->currentIndex() == 2) else if(ui->mainTab->currentIndex() == 2)
loadPragmas(); loadPragmas();
retval = true; retval = true;
@@ -324,7 +324,7 @@ void MainWindow::fileNew()
statusReadOnlyLabel->setVisible(false); statusReadOnlyLabel->setVisible(false);
loadExtensionsFromSettings(); loadExtensionsFromSettings();
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
openSqlTab(true); openSqlTab(true);
createTable(); createTable();
} }
@@ -348,7 +348,7 @@ void MainWindow::populateStructure()
if(old_table_index == -1 && ui->comboBrowseTable->count()) // If the old table couldn't be found anymore but there is another table, select that if(old_table_index == -1 && ui->comboBrowseTable->count()) // If the old table couldn't be found anymore but there is another table, select that
ui->comboBrowseTable->setCurrentIndex(0); ui->comboBrowseTable->setCurrentIndex(0);
else if(old_table_index == -1) // If there aren't any tables to be selected anymore, clear the table view else if(old_table_index == -1) // If there aren't any tables to be selected anymore, clear the table view
populateTable(""); clearTableBrowser();
else // Under normal circumstances just select the old table again else // Under normal circumstances just select the old table again
ui->comboBrowseTable->setCurrentIndex(old_table_index); ui->comboBrowseTable->setCurrentIndex(old_table_index);
@@ -379,6 +379,16 @@ void MainWindow::populateStructure()
ui->dbTreeWidget->resizeColumnToContents(3); ui->dbTreeWidget->resizeColumnToContents(3);
} }
void MainWindow::clearTableBrowser()
{
if (!ui->dataTable->model())
return;
ui->dataTable->setModel(0);
if(qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader()))
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(0);
}
void MainWindow::populateTable(QString tablename) void MainWindow::populateTable(QString tablename)
{ {
// Early exit if the Browse Data tab isn't visible as there is no need to update it in this case // Early exit if the Browse Data tab isn't visible as there is no need to update it in this case
@@ -388,17 +398,16 @@ void MainWindow::populateTable(QString tablename)
// Remove the model-view link if the table name is empty in order to remove any data from the view // Remove the model-view link if the table name is empty in order to remove any data from the view
if(ui->comboBrowseTable->model()->rowCount(ui->comboBrowseTable->rootModelIndex()) == 0 && tablename.isEmpty()) if(ui->comboBrowseTable->model()->rowCount(ui->comboBrowseTable->rootModelIndex()) == 0 && tablename.isEmpty())
{ {
if (!ui->dataTable->model()) clearTableBrowser();
return;
ui->dataTable->setModel(0);
if(qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader()))
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(0);
return; return;
} }
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
// Default parameter -> use current table name
if(tablename.isNull())
tablename = ui->comboBrowseTable->currentText();
// Set model // Set model
bool reconnectSelectionSignals = false; bool reconnectSelectionSignals = false;
if(ui->dataTable->model() == 0) if(ui->dataTable->model() == 0)
@@ -684,7 +693,7 @@ void MainWindow::setRecordsetLabel()
void MainWindow::browseRefresh() void MainWindow::browseRefresh()
{ {
db.updateSchema(); db.updateSchema();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
void MainWindow::createTable() void MainWindow::createTable()
@@ -698,7 +707,7 @@ void MainWindow::createTable()
if(dialog.exec()) if(dialog.exec())
{ {
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
} }
@@ -740,7 +749,7 @@ void MainWindow::deleteObject()
QMessageBox::warning(this, QApplication::applicationName(), error); QMessageBox::warning(this, QApplication::applicationName(), error);
} else { } else {
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
changeTreeSelection(); changeTreeSelection();
} }
} }
@@ -761,7 +770,7 @@ void MainWindow::editTable()
if(dialog.exec()) if(dialog.exec())
{ {
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
} }
@@ -997,7 +1006,7 @@ void MainWindow::mainTabSelected(int tabindex)
} else if(tabindex == 1) { } else if(tabindex == 1) {
m_currentTabTableModel = m_browseTableModel; m_currentTabTableModel = m_browseTableModel;
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} else if(tabindex == 2) { } else if(tabindex == 2) {
loadPragmas(); loadPragmas();
} else if(tabindex == 3) { } else if(tabindex == 3) {
@@ -1024,7 +1033,7 @@ void MainWindow::importTableFromCSV()
if(dialog.exec()) if(dialog.exec())
{ {
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
QMessageBox::information(this, QApplication::applicationName(), tr("Import completed")); QMessageBox::information(this, QApplication::applicationName(), tr("Import completed"));
} }
} }
@@ -1069,7 +1078,7 @@ void MainWindow::fileRevert()
{ {
db.revertAll(); db.revertAll();
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
} }
} }
@@ -1137,7 +1146,7 @@ void MainWindow::importDatabaseFromSQL()
fileOpen(newDbFile); fileOpen(newDbFile);
} else { } else {
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
} }
@@ -1591,7 +1600,7 @@ void MainWindow::reloadSettings()
// Refresh view // Refresh view
populateStructure(); populateStructure();
populateTable(ui->comboBrowseTable->currentText()); populateTable();
} }
void MainWindow::httpresponse(QNetworkReply *reply) void MainWindow::httpresponse(QNetworkReply *reply)
@@ -2092,7 +2101,7 @@ bool MainWindow::loadProject(QString filename)
QByteArray temp = QByteArray::fromBase64(attrData.toUtf8()); QByteArray temp = QByteArray::fromBase64(attrData.toUtf8());
QDataStream stream(temp); QDataStream stream(temp);
stream >> browseTableSettings; stream >> browseTableSettings;
populateTable(ui->comboBrowseTable->currentText()); // Refresh view populateTable(); // Refresh view
ui->dataTable->sortByColumn(browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderIndex, ui->dataTable->sortByColumn(browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderIndex,
browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderMode); browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderMode);
showRowidColumn(browseTableSettings[ui->comboBrowseTable->currentText()].showRowid); showRowidColumn(browseTableSettings[ui->comboBrowseTable->currentText()].showRowid);
@@ -2446,7 +2455,7 @@ void MainWindow::editDataColumnDisplayFormat()
browseTableSettings[current_table].displayFormats.remove(field_number); browseTableSettings[current_table].displayFormats.remove(field_number);
// Refresh view // Refresh view
populateTable(current_table); populateTable();
} }
} }

View File

@@ -160,7 +160,8 @@ private slots:
void changeTreeSelection(); void changeTreeSelection();
void fileNew(); void fileNew();
void populateStructure(); void populateStructure();
void populateTable(QString tablename); void populateTable(QString tablename = QString());
void clearTableBrowser();
bool fileClose(); bool fileClose();
void addRecord(); void addRecord();
void deleteRecord(); void deleteRecord();