Finish main part of the recent refactoring effort · Chunde/sqlitebrowser@38144bb · GitHub
Skip to content

Commit 38144bb

Browse files
committed
Finish main part of the recent refactoring effort
This finally gets rid of the DBBrowserObject class entirely and moves all its functionality to the newer classes in the sqlb namespace. I'm still not entirely happy with this but at least things should be a little more consistent now.
1 parent 3839256 commit 38144bb

14 files changed

Lines changed: 79 additions & 98 deletions

‎src/DbStructureModel.cpp‎

Lines changed: 11 additions & 26 deletions

‎src/DbStructureModel.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <QAbstractItemModel>
55

66
class DBBrowserDB;
7-
class DBBrowserObject;
87
class QTreeWidgetItem;
8+
namespace sqlb { class Object; typedef QSharedPointer<Object> ObjectPtr; }
99

1010
class DbStructureModel : public QAbstractItemModel
1111
{
@@ -33,7 +33,7 @@ class DbStructureModel : public QAbstractItemModel
3333
QTreeWidgetItem* rootItem;
3434
DBBrowserDB& m_db;
3535

36-
QTreeWidgetItem* addNode(QTreeWidgetItem* parent, const DBBrowserObject& object);
36+
QTreeWidgetItem* addNode(QTreeWidgetItem* parent, const sqlb::ObjectPtr& object);
3737
};
3838

3939
#endif

‎src/EditIndexDialog.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const QString& indexName, bool
1717
ui->setupUi(this);
1818

1919
// Get list of tables, sort it alphabetically and fill the combobox
20-
QMultiMap<QString, DBBrowserObject> dbobjs;
21-
QList<DBBrowserObject> tables = pdb.objMap.values("table");
20+
objectMap dbobjs;
21+
QList<sqlb::ObjectPtr> tables = pdb.objMap.values("table");
2222
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
23-
dbobjs.insert((*it).getname(), (*it));
23+
dbobjs.insert((*it)->name(), (*it));
2424
ui->comboTableName->blockSignals(true);
2525
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
26-
ui->comboTableName->addItem(QIcon(QString(":icons/table")), (*it).getname());
26+
ui->comboTableName->addItem(QIcon(QString(":icons/table")), (*it)->name());
2727
ui->comboTableName->blockSignals(false);
2828

2929
QHeaderView *tableHeaderView = ui->tableIndexColumns->horizontalHeader();

‎src/EditTableDialog.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
272272
if(!m_bNewTable)
273273
{
274274
sqlb::FieldVector pk = m_table.primaryKey();
275-
foreach(const DBBrowserObject& fkobj, pdb.objMap.values("table"))
275+
foreach(const sqlb::ObjectPtr& fkobj, pdb.objMap.values("table"))
276276
{
277-
QList<sqlb::ConstraintPtr> fks = fkobj.object.dynamicCast<sqlb::Table>()->constraints(sqlb::FieldVector(), sqlb::Constraint::ForeignKeyConstraintType);
277+
QList<sqlb::ConstraintPtr> fks = fkobj.dynamicCast<sqlb::Table>()->constraints(sqlb::FieldVector(), sqlb::Constraint::ForeignKeyConstraintType);
278278
foreach(sqlb::ConstraintPtr fkptr, fks)
279279
{
280280
QSharedPointer<sqlb::ForeignKeyClause> fk = fkptr.dynamicCast<sqlb::ForeignKeyClause>();
@@ -284,7 +284,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
284284
{
285285
QMessageBox::warning(this, qApp->applicationName(), tr("This column is referenced in a foreign key in table %1 and thus "
286286
"its name cannot be changed.")
287-
.arg(fkobj.getname()));
287+
.arg(fkobj->name()));
288288
// Reset the name to the old value but avoid calling this method again for that automatic change
289289
ui->treeWidget->blockSignals(true);
290290
item->setText(column, oldFieldName);

‎src/ExportDataDialog.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ ExportDataDialog::ExportDataDialog(DBBrowserDB& db, ExportFormats format, QWidge
4040
{
4141
// Get list of tables to export
4242
objectMap objects = pdb.getBrowsableObjects();
43-
foreach(const DBBrowserObject& obj, objects)
44-
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(obj.gettype())), obj.getname()));
43+
foreach(const sqlb::ObjectPtr& obj, objects)
44+
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(sqlb::Object::typeToString(obj->type()))), obj->name()));
4545

4646
// Sort list of tables and select the table specified in the selection parameter or alternatively the first one
4747
ui->listTables->model()->sort(0);

‎src/ExportSqlDialog.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ExportSqlDialog::ExportSqlDialog(DBBrowserDB* db, QWidget* parent, const QString
2727
// Get list of tables to export
2828
objectMap objects = pdb->getBrowsableObjects();
2929
for(auto it=objects.constBegin();it!=objects.constEnd();++it) {
30-
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(it.value().gettype())), it.value().getname()));
30+
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg((*it)->type())), (*it)->name()));
3131
}
3232

3333
// Sort list of tables and select the table specified in the

‎src/ForeignKeyEditorDelegate.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ ForeignKeyEditorDelegate::ForeignKeyEditorDelegate(const DBBrowserDB& db, sqlb::
8181
{
8282
const auto objects = m_db.getBrowsableObjects();
8383
for (auto& obj : objects) {
84-
if (obj.gettype() == sqlb::Object::Types::Table) {
85-
QString tableName = obj.object->name();
86-
m_tablesIds.insert(tableName, obj.object.dynamicCast<sqlb::Table>()->fieldNames());
84+
if (obj->type() == sqlb::Object::Types::Table) {
85+
QString tableName = obj->name();
86+
m_tablesIds.insert(tableName, obj.dynamicCast<sqlb::Table>()->fieldNames());
8787
}
8888
}
8989
}

‎src/ImportCsvDialog.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ void ImportCsvDialog::accept()
186186
objectMap objects = pdb->getBrowsableObjects();
187187
for(auto it=objects.constBegin();it!=objects.constEnd();++it)
188188
{
189-
if(it.value().gettype() == sqlb::Object::Types::Table && it.value().getname() == ui->editName->text())
189+
if((*it)->type() == sqlb::Object::Types::Table && (*it)->name() == ui->editName->text())
190190
{
191-
if((size_t)it.value().object.dynamicCast<sqlb::Table>()->fields().size() != csv.columns())
191+
if((size_t)(*it).dynamicCast<sqlb::Table>()->fields().size() != csv.columns())
192192
{
193193
QMessageBox::warning(this, QApplication::applicationName(),
194194
tr("There is already a table of that name and an import into an existing table is only possible if the number of columns match."));

‎src/MainWindow.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ void MainWindow::populateStructure()
365365
SqlUiLexer::TablesAndColumnsMap tablesToColumnsMap;
366366
for(auto it=tab.constBegin();it!=tab.constEnd();++it)
367367
{
368-
QString objectname = it.value().getname();
368+
QString objectname = (*it)->name();
369369

370-
sqlb::FieldInfoList fi = it->object->fieldInformation();
370+
sqlb::FieldInfoList fi = (*it)->fieldInformation();
371371
foreach(const sqlb::FieldInfo& f, fi)
372372
tablesToColumnsMap[objectname].append(f.name);
373373
}

‎src/VacuumDialog.cpp‎

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)