Skip to content

Commit

Permalink
Rename sqlb::Object::ObjectTypes enum to sqlb::Object::Types
Browse files Browse the repository at this point in the history
The 'Object' parts seemed a little redundant before.
  • Loading branch information
MKleusberg committed Jan 23, 2017
1 parent 649f2b8 commit ebc3869
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
18 changes: 9 additions & 9 deletions src/DbStructureModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ void DbStructureModel::reloadData()
QString type;
switch((*it).gettype())
{
case sqlb::Object::ObjectTypes::Table: type = "table"; break;
case sqlb::Object::ObjectTypes::Index: type = "index"; break;
case sqlb::Object::ObjectTypes::Trigger: type = "trigger"; break;
case sqlb::Object::ObjectTypes::View: type = "view"; break;
case sqlb::Object::Types::Table: type = "table"; break;
case sqlb::Object::Types::Index: type = "index"; break;
case sqlb::Object::Types::Trigger: type = "trigger"; break;
case sqlb::Object::Types::View: type = "view"; break;
}
QTreeWidgetItem* item = addNode(typeToParentItem.value(type), *it);

// If it is a table or view add the field nodes
if((*it).gettype() == sqlb::Object::ObjectTypes::Table || (*it).gettype() == sqlb::Object::ObjectTypes::View)
if((*it).gettype() == sqlb::Object::Types::Table || (*it).gettype() == sqlb::Object::Types::View)
{
// Add extra node for browsable section
addNode(typeToParentItem.value("browsable"), *it);
Expand Down Expand Up @@ -290,10 +290,10 @@ QTreeWidgetItem* DbStructureModel::addNode(QTreeWidgetItem* parent, const DBBrow
QString type;
switch(object.gettype())
{
case sqlb::Object::ObjectTypes::Table: type = "table"; break;
case sqlb::Object::ObjectTypes::Index: type = "index"; break;
case sqlb::Object::ObjectTypes::Trigger: type = "trigger"; break;
case sqlb::Object::ObjectTypes::View: type = "view"; break;
case sqlb::Object::Types::Table: type = "table"; break;
case sqlb::Object::Types::Index: type = "index"; break;
case sqlb::Object::Types::Trigger: type = "trigger"; break;
case sqlb::Object::Types::View: type = "view"; break;
}

QTreeWidgetItem *item = new QTreeWidgetItem(parent);
Expand Down
2 changes: 1 addition & 1 deletion src/ForeignKeyEditorDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ForeignKeyEditorDelegate::ForeignKeyEditorDelegate(const DBBrowserDB& db, sqlb::
{
const auto objects = m_db.getBrowsableObjects();
for (auto& obj : objects) {
if (obj.gettype() == sqlb::Object::ObjectTypes::Table) {
if (obj.gettype() == sqlb::Object::Types::Table) {
QString tableName = obj.object->name();
m_tablesIds.insert(tableName, obj.object.dynamicCast<sqlb::Table>()->fieldNames());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImportCsvDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void ImportCsvDialog::accept()
objectMap objects = pdb->getBrowsableObjects();
for(auto it=objects.constBegin();it!=objects.constEnd();++it)
{
if(it.value().gettype() == sqlb::Object::ObjectTypes::Table && it.value().getname() == ui->editName->text())
if(it.value().gettype() == sqlb::Object::Types::Table && it.value().getname() == ui->editName->text())
{
if((size_t)it.value().object.dynamicCast<sqlb::Table>()->fields().size() != csv.columns())
{
Expand Down
8 changes: 4 additions & 4 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,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)->type() == sqlb::Object::ObjectTypes::Table && !db.readOnly();
bool editable = db.getObjectByName(tablename)->type() == sqlb::Object::Types::Table && !db.readOnly();
ui->buttonNewRecord->setEnabled(editable);
ui->buttonDeleteRecord->setEnabled(editable);
ui->dataTable->setEditTriggers(editable ? QAbstractItemView::SelectedClicked | QAbstractItemView::AnyKeyPressed | QAbstractItemView::EditKeyPressed : QAbstractItemView::NoEditTriggers);
Expand Down Expand Up @@ -817,7 +817,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())->type() == sqlb::Object::ObjectTypes::Table);
(db.getObjectByName(ui->comboBrowseTable->currentText())->type() == sqlb::Object::Types::Table);

// Enable or disable the Apply, Null, & Import buttons in the Edit Cell
// dock depending on the value of the "isEditingAllowed" bool above
Expand All @@ -841,7 +841,7 @@ void MainWindow::dataTableSelectionChanged(const QModelIndex& index)
}

bool editingAllowed = (m_currentTabTableModel == m_browseTableModel) &&
(db.getObjectByName(ui->comboBrowseTable->currentText())->type() == sqlb::Object::ObjectTypes::Table);
(db.getObjectByName(ui->comboBrowseTable->currentText())->type() == sqlb::Object::Types::Table);

// Don't allow editing of other objects than tables
editDock->setReadOnly(!editingAllowed);
Expand Down Expand Up @@ -2238,7 +2238,7 @@ void MainWindow::showDataColumnPopupMenu(const QPoint& pos)
void MainWindow::showRecordPopupMenu(const QPoint& pos)
{
const QString sCurrentTable = ui->comboBrowseTable->currentText();
if(!(db.getObjectByName(sCurrentTable)->type() == sqlb::Object::ObjectTypes::Table && !db.readOnly()))
if(!(db.getObjectByName(sCurrentTable)->type() == sqlb::Object::Types::Table && !db.readOnly()))
return;

int row = ui->dataTable->verticalHeader()->logicalIndexAt(pos);
Expand Down
22 changes: 11 additions & 11 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ bool DBBrowserDB::dump(const QString& filename,
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
{
// Make sure it's not a table again
if(it.value().gettype() == sqlb::Object::ObjectTypes::Table)
if(it.value().gettype() == sqlb::Object::Types::Table)
continue;

// Write the SQL string used to create this object to the output file
Expand Down Expand Up @@ -1076,11 +1076,11 @@ bool DBBrowserDB::renameColumn(const QString& tablename, const sqlb::Table& tabl
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
{
// If this object references the table and it's not the table itself save it's SQL string
if((*it).getTableName() == tablename && (*it).gettype() != sqlb::Object::ObjectTypes::Table)
if((*it).getTableName() == tablename && (*it).gettype() != sqlb::Object::Types::Table)
{
// If this is an index, update the fields first. This highly increases the chance that the SQL statement won't throw an
// error later on when we try to recreate it.
if((*it).gettype() == sqlb::Object::ObjectTypes::Index)
if((*it).gettype() == sqlb::Object::Types::Index)
{
sqlb::IndexPtr idx = (*it).object.dynamicCast<sqlb::Index>();
for(int i=0;i<idx->columns().size();i++)
Expand Down Expand Up @@ -1240,34 +1240,34 @@ void DBBrowserDB::updateSchema( )
QString val_temp = QString::fromUtf8((const char*)sqlite3_column_text(vm, 4));
val_sql.replace("\r", "");

sqlb::Object::ObjectTypes type;
sqlb::Object::Types type;
if(val_type == "table")
type = sqlb::Object::ObjectTypes::Table;
type = sqlb::Object::Types::Table;
else if(val_type == "index")
type = sqlb::Object::ObjectTypes::Index;
type = sqlb::Object::Types::Index;
else if(val_type == "trigger")
type = sqlb::Object::ObjectTypes::Trigger;
type = sqlb::Object::Types::Trigger;
else if(val_type == "view")
type = sqlb::Object::ObjectTypes::View;
type = sqlb::Object::Types::View;
else
continue;

DBBrowserObject obj(val_name, val_sql, type, val_tblname);
if((type == sqlb::Object::ObjectTypes::Table || type == sqlb::Object::ObjectTypes::Index) && !val_sql.isEmpty())
if((type == sqlb::Object::Types::Table || type == sqlb::Object::Types::Index) && !val_sql.isEmpty())
{
obj.object = sqlb::Object::parseSQL(type, val_sql);
if(val_temp == "1")
obj.object->setTemporary(true);

// For virtual tables query the column list using the SQLite pragma
if(type == sqlb::Object::ObjectTypes::Table && obj.object.dynamicCast<sqlb::Table>()->isVirtual())
if(type == sqlb::Object::Types::Table && obj.object.dynamicCast<sqlb::Table>()->isVirtual())
{
sqlb::TablePtr tab = obj.object.dynamicCast<sqlb::Table>();
auto columns = queryColumnInformation(val_name);
foreach(const auto& column, columns)
tab->addField(sqlb::FieldPtr(new sqlb::Field(column.first, column.second)));
}
} else if(type == sqlb::Object::ObjectTypes::View) {
} else if(type == sqlb::Object::Types::View) {
// For views we currently can't rely on our grammar parser to get the column list. Use the pragma offered by SQLite instead
auto columns = queryColumnInformation(val_name);
sqlb::Table* view_dummy = new sqlb::Table("");
Expand Down
6 changes: 3 additions & 3 deletions src/sqlitedb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class DBBrowserObject
{
public:
DBBrowserObject() : name( "" ) { }
DBBrowserObject(const QString& wname, const QString& wsql, sqlb::Object::ObjectTypes wtype, const QString& tbl_name)
DBBrowserObject(const QString& wname, const QString& wsql, sqlb::Object::Types wtype, const QString& tbl_name)
: name( wname), sql( wsql ), type(wtype), table_name(tbl_name)
{ }

QString getname() const { return name; }
QString getsql() const { return sql; }
sqlb::Object::ObjectTypes gettype() const { return type; }
sqlb::Object::Types gettype() const { return type; }
QString getTableName() const { return table_name; }

sqlb::ObjectPtr object;
private:
QString name;
QString sql;
sqlb::Object::ObjectTypes type;
sqlb::Object::Types type;
QString table_name; // The name of the table this object references, interesting for views, triggers and indices
};

Expand Down
2 changes: 1 addition & 1 deletion src/sqlitetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void SqliteTableModel::setTable(const QString& table, const QVector<QString>& di
m_vDataTypes.push_back(SQLITE_INTEGER);

bool allOk = false;
if(m_db.getObjectByName(table)->type() == sqlb::Object::ObjectTypes::Table)
if(m_db.getObjectByName(table)->type() == sqlb::Object::Types::Table)
{
sqlb::TablePtr t = m_db.getObjectByName(table).dynamicCast<sqlb::Table>();
if(t && t->fields().size()) // parsing was OK
Expand Down
6 changes: 3 additions & 3 deletions src/sqlitetypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ class CreateIndexWalker
antlr::RefAST m_root;
};

ObjectPtr Object::parseSQL(Object::ObjectTypes type, const QString& sSQL)
ObjectPtr Object::parseSQL(Object::Types type, const QString& sSQL)
{
// Parse SQL statement according to type
ObjectPtr result;
switch(type)
{
case Object::ObjectTypes::Table:
case Object::Types::Table:
result = Table::parseSQL(sSQL);
break;
case Object::ObjectTypes::Index:
case Object::Types::Index:
result = Index::parseSQL(sSQL);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions src/sqlitetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QStringList fieldVectorToFieldNames(const sqlb::FieldVector& vector);
class Object
{
public:
enum ObjectTypes
enum Types
{
Table,
Index,
Expand All @@ -44,7 +44,7 @@ class Object
explicit Object(const QString& name): m_name(name), m_temporary(false), m_fullyParsed(false) {}
virtual ~Object() {}

virtual ObjectTypes type() const = 0;
virtual Types type() const = 0;

void setName(const QString& name) { m_name = name; }
const QString& name() const { return m_name; }
Expand Down Expand Up @@ -74,7 +74,7 @@ class Object
* @param sSQL The create statement.
* @return The parsed database object. The object may be empty if parsing failed.
*/
static ObjectPtr parseSQL(Object::ObjectTypes type, const QString& sSQL);
static ObjectPtr parseSQL(Object::Types type, const QString& sSQL);

protected:
QString m_name;
Expand Down Expand Up @@ -223,7 +223,7 @@ class Table : public Object
explicit Table(const QString& name): Object(name), m_rowidColumn("_rowid_") {}
virtual ~Table();

virtual ObjectTypes type() const { return Object::Table; }
virtual Types type() const { return Object::Table; }

const FieldVector& fields() const { return m_fields; }

Expand Down Expand Up @@ -320,7 +320,7 @@ class Index : public Object
explicit Index(const QString& name): Object(name), m_unique(false) {}
virtual ~Index();

virtual ObjectTypes type() const { return Object::Index; }
virtual Types type() const { return Object::Index; }

virtual QString baseTable() const { return m_table; }

Expand Down

0 comments on commit ebc3869

Please sign in to comment.