Skip to content

Commit

Permalink
Add index columns to database structure tree
Browse files Browse the repository at this point in the history
In the Database Structure tab and dock tree widgets, make the indices
expandable and show their indexed columns as child nodes.
  • Loading branch information
MKleusberg committed Jan 27, 2017
1 parent 28ddbc4 commit 901e087
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/DbStructureModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ void DbStructureModel::reloadData()
// Object node
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString((*it)->type())), *it);

// If it is a table or view add the field nodes
// If it is a table or view add the field nodes, add an extra node for the browsable section
if((*it)->type() == sqlb::Object::Types::Table || (*it)->type() == sqlb::Object::Types::View)
{
// Add extra node for browsable section
addNode(typeToParentItem.value("browsable"), *it);

// Add field nodes
// Add field nodes if there are any
sqlb::FieldInfoList fieldList = (*it)->fieldInformation();
if(!fieldList.empty())
{
QStringList pk_columns;
if((*it)->type() == sqlb::Object::Types::Table)
{
Expand All @@ -195,7 +196,6 @@ void DbStructureModel::reloadData()
pk_columns.push_back(pk_col->name());

}
sqlb::FieldInfoList fieldList = (*it)->fieldInformation();
foreach(const sqlb::FieldInfo& field, fieldList)
{
QTreeWidgetItem *fldItem = new QTreeWidgetItem(item);
Expand Down
8 changes: 8 additions & 0 deletions src/sqlitetypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,14 @@ QString Index::sql() const
return sql + ";";
}

FieldInfoList Index::fieldInformation() const
{
FieldInfoList result;
foreach(IndexedColumnPtr c, m_columns)
result.append({c->name(), c->order(), c->toString(" ", " ")});
return result;
}

ObjectPtr Index::parseSQL(const QString& sSQL)
{
std::stringstream s;
Expand Down
2 changes: 2 additions & 0 deletions src/sqlitetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ class Index : public Object
*/
static ObjectPtr parseSQL(const QString& sSQL);

virtual FieldInfoList fieldInformation() const;

private:
QStringList columnSqlList() const;

Expand Down

0 comments on commit 901e087

Please sign in to comment.