mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Code refactoring
This changes the class structure in the sqlb namespace as well as the DBBrowserObject class. The rest of the commit are changes that are required by the modifications in sqlb and DBBrowserObject. The idea behind this refactoring is this: we currently have the DBBrowserObject class which holds some basic information about the database object (name, type, SQL string, etc.). It also contains a sqlb::Table and a sqlb::Index object. Those are used if the type of the object is table or index and they contain a whole lot more information on the object than the DBBrowserObject class, including the name, the type, the SQL string, etc. So we have a duplication here. There are two class structures for storing the same information. This has historic reasons but other than that there is no point in keeping it this way. With this commit I start the work of consolidating the sqlb classes in order to get rid of the DBBrowserObject class entirely. This commit only starts this task, it doesn't finish it. This is why it is a little messy here and there, but then again the old structure was a little messy, too. We will need at least a very basic trigger and view parser before finishing this is even possible. When this is done, I hope the ode will be much easier to read and understand. But even in the current state there already is some progress: we save a little bit of memory, don't copy big objects all the time anymore, and replace a lot of unnecessary string comparisons with integer comparisons.
This commit is contained in:
@@ -366,9 +366,9 @@ void MainWindow::populateStructure()
|
||||
{
|
||||
QString objectname = it.value().getname();
|
||||
|
||||
for(int i=0; i < (*it).table.fields().size(); ++i)
|
||||
for(int i=0; i < (*it).object.dynamicCast<sqlb::Table>()->fields().size(); ++i)
|
||||
{
|
||||
QString fieldname = (*it).table.fields().at(i)->name();
|
||||
QString fieldname = (*it).object.dynamicCast<sqlb::Table>()->fields().at(i)->name();
|
||||
tablesToColumnsMap[objectname].append(fieldname);
|
||||
}
|
||||
}
|
||||
@@ -429,7 +429,7 @@ void MainWindow::populateTable()
|
||||
} else {
|
||||
QVector<QString> v;
|
||||
bool only_defaults = true;
|
||||
const sqlb::FieldVector& tablefields = db.getObjectByName(tablename).table.fields();
|
||||
const sqlb::FieldVector& tablefields = db.getObjectByName(tablename).dynamicCast<sqlb::Table>()->fields();
|
||||
for(int i=0; i<tablefields.size(); ++i)
|
||||
{
|
||||
QString format = tableIt.value().displayFormats[i+1];
|
||||
@@ -498,7 +498,7 @@ void MainWindow::populateTable()
|
||||
}
|
||||
|
||||
// Activate the add and delete record buttons and editing only if a table has been selected
|
||||
bool editable = db.getObjectByName(tablename).gettype() == "table" && !db.readOnly();
|
||||
bool editable = db.getObjectByName(tablename)->type() == sqlb::Object::ObjectTypes::Table && !db.readOnly();
|
||||
ui->buttonNewRecord->setEnabled(editable);
|
||||
ui->buttonDeleteRecord->setEnabled(editable);
|
||||
ui->dataTable->setEditTriggers(editable ? QAbstractItemView::SelectedClicked | QAbstractItemView::AnyKeyPressed | QAbstractItemView::EditKeyPressed : QAbstractItemView::NoEditTriggers);
|
||||
@@ -816,7 +816,7 @@ void MainWindow::doubleClickTable(const QModelIndex& index)
|
||||
|
||||
// * Don't allow editing of other objects than tables (on the browse table) *
|
||||
bool isEditingAllowed = (m_currentTabTableModel == m_browseTableModel) &&
|
||||
(db.getObjectByName(ui->comboBrowseTable->currentText()).gettype() == "table");
|
||||
(db.getObjectByName(ui->comboBrowseTable->currentText())->type() == sqlb::Object::ObjectTypes::Table);
|
||||
|
||||
// Enable or disable the Apply, Null, & Import buttons in the Edit Cell
|
||||
// dock depending on the value of the "isEditingAllowed" bool above
|
||||
@@ -840,7 +840,7 @@ void MainWindow::dataTableSelectionChanged(const QModelIndex& index)
|
||||
}
|
||||
|
||||
bool editingAllowed = (m_currentTabTableModel == m_browseTableModel) &&
|
||||
(db.getObjectByName(ui->comboBrowseTable->currentText()).gettype() == "table");
|
||||
(db.getObjectByName(ui->comboBrowseTable->currentText())->type() == sqlb::Object::ObjectTypes::Table);
|
||||
|
||||
// Don't allow editing of other objects than tables
|
||||
editDock->setReadOnly(!editingAllowed);
|
||||
@@ -2195,16 +2195,16 @@ void MainWindow::copyCurrentCreateStatement()
|
||||
void MainWindow::jumpToRow(const QString& table, QString column, const QByteArray& value)
|
||||
{
|
||||
// First check if table exists
|
||||
DBBrowserObject obj = db.getObjectByName(table);
|
||||
if(obj.getname().size() == 0)
|
||||
sqlb::TablePtr obj = db.getObjectByName(table).dynamicCast<sqlb::Table>();
|
||||
if(!obj)
|
||||
return;
|
||||
|
||||
// If no column name is set, assume the primary key is meant
|
||||
if(!column.size())
|
||||
column = obj.table.fields().at(obj.table.findPk())->name();
|
||||
column = obj->fields().at(obj->findPk())->name();
|
||||
|
||||
// If column doesn't exist don't do anything
|
||||
int column_index = obj.table.findField(column);
|
||||
int column_index = obj->findField(column);
|
||||
if(column_index == -1)
|
||||
return;
|
||||
|
||||
@@ -2232,7 +2232,7 @@ void MainWindow::showDataColumnPopupMenu(const QPoint& pos)
|
||||
void MainWindow::showRecordPopupMenu(const QPoint& pos)
|
||||
{
|
||||
const QString sCurrentTable = ui->comboBrowseTable->currentText();
|
||||
if (!(db.getObjectByName(sCurrentTable).gettype() == "table" && !db.readOnly()))
|
||||
if(!(db.getObjectByName(sCurrentTable)->type() == sqlb::Object::ObjectTypes::Table && !db.readOnly()))
|
||||
return;
|
||||
|
||||
int row = ui->dataTable->verticalHeader()->logicalIndexAt(pos);
|
||||
@@ -2257,7 +2257,7 @@ void MainWindow::editDataColumnDisplayFormat()
|
||||
// column is always the rowid column. Ultimately, get the column name from the column object
|
||||
QString current_table = ui->comboBrowseTable->currentText();
|
||||
int field_number = sender()->property("clicked_column").toInt();
|
||||
QString field_name = db.getObjectByName(current_table).table.fields().at(field_number-1)->name();
|
||||
QString field_name = db.getObjectByName(current_table).dynamicCast<sqlb::Table>()->fields().at(field_number-1)->name();
|
||||
|
||||
// Get the current display format of the field
|
||||
QString current_displayformat = browseTableSettings[current_table].displayFormats[field_number];
|
||||
|
||||
Reference in New Issue
Block a user