Code refactoring · jiangdon2007/sqlitebrowser@bf505ed · GitHub
Skip to content

Commit bf505ed

Browse files
committed
Code refactoring
This commit refactors vast parts of the sqlitetypes.h interface. Its main goals are: less code, easier code, a more modern interface, reduced likelihood for strange errors and more flexibility for future extensions. The main reason why the sqlitetypes.h functions were working so well in DB4S was not because they were that stable but because they were extremely interlinked with the rest of the code. This is fine because we do not plan to ship them as a separate library. But it makes it hard to find the obvious spot to fix an issue or to put a new function. It can always be done in the sqlitetypes function or in the rest of the DB4S code because it is just not clear what the interface between the two should look like. This is supposed to be improved by this commit. One main thing here is to make ownership of objects a bit clearer. In theory the new code should be faster too but that difference will be neglectable from a user POV. This commit also fixes a hidden bug which caused all table constraints to be removed in the Edit Table dialog when a single field was removed from the table. This is all still WIP and more work is needed to be done here.
1 parent f3e6aec commit bf505ed

16 files changed

Lines changed: 688 additions & 795 deletions

‎src/AddRecordDialog.cpp‎

Lines changed: 16 additions & 17 deletions

‎src/DbStructureModel.cpp‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,7 @@ void DbStructureModel::buildTree(QTreeWidgetItem* parent, const QString& schema)
326326
{
327327
QStringList pk_columns;
328328
if(it->type() == sqlb::Object::Types::Table)
329-
{
330-
sqlb::FieldVector pk = it.dynamicCast<sqlb::Table>()->primaryKey();
331-
for(const sqlb::FieldPtr& pk_col : pk)
332-
pk_columns.push_back(pk_col->name());
333-
334-
}
329+
pk_columns = std::dynamic_pointer_cast<sqlb::Table>(it)->primaryKey();
335330
for(const sqlb::FieldInfo& field : fieldList)
336331
{
337332
QTreeWidgetItem *fldItem = new QTreeWidgetItem(item);

‎src/DbStructureModel.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define DBSTRUCTUREMODEL_H
33

44
#include <QAbstractItemModel>
5+
#include <memory>
56

67
class DBBrowserDB;
78
class QTreeWidgetItem;
8-
namespace sqlb { class Object; typedef QSharedPointer<Object> ObjectPtr; }
9+
namespace sqlb { class Object; using ObjectPtr = std::shared_ptr<Object>; }
910

1011
class DbStructureModel : public QAbstractItemModel
1112
{

‎src/EditIndexDialog.cpp‎

Lines changed: 30 additions & 31 deletions

0 commit comments

Comments
 (0)