aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp56
1 files changed, 40 insertions, 16 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp
index 123c4df..436ab50 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp
@@ -14,6 +14,7 @@
#include "dialogs/versionconvertsummarydialog.h"
#include "db/invaliddb.h"
#include "services/notifymanager.h"
+#include "common/compatibility.h"
#include <QMimeData>
#include <QDebug>
#include <QFile>
@@ -202,6 +203,7 @@ QList<Config::DbGroupPtr> DbTreeModel::childsToConfig(QStandardItem *item)
group->referencedDbName = dbTreeItem->text();
group->order = i;
group->open = dbTreeItem->getDb()->isOpen();
+ group->dbExpanded = treeView->isExpanded(dbTreeItem->index());
groups += group;
break;
}
@@ -260,10 +262,7 @@ void DbTreeModel::restoreGroup(const Config::DbGroupPtr& group, QList<Db*>* dbLi
// Instead of that, we just check if the database is already open (by DbManager)
// and call proper handler to refresh database's schema and create tree nodes.
if (db->isOpen())
- {
- dbConnected(db);
- treeView->expand(item->index());
- }
+ dbConnected(db, group->dbExpanded);
}
else
{
@@ -394,7 +393,7 @@ QVariant DbTreeModel::data(const QModelIndex &index, int role) const
QString DbTreeModel::getToolTip(DbTreeItem* item) const
{
if (!item)
- return QString::null;
+ return QString();
switch (item->getType())
{
@@ -405,7 +404,7 @@ QString DbTreeModel::getToolTip(DbTreeItem* item) const
default:
break;
}
- return QString::null;
+ return QString();
}
QString DbTreeModel::getDbToolTip(DbTreeItem* item) const
@@ -552,13 +551,13 @@ QList<QStandardItem *> DbTreeModel::refreshSchemaTables(const QStringList &table
StrHash<QList<QStandardItem*>> DbTreeModel::refreshSchemaTableColumns(const StrHash<QStringList> &columns)
{
QStringList sortedColumns;
- bool sort = CFG_UI.General.SortColumns.get();
+ bool doSort = CFG_UI.General.SortColumns.get();
StrHash<QList<QStandardItem*>> items;
for (const QString& key : columns.keys())
{
sortedColumns = columns[key];
- if (sort)
- qSort(sortedColumns);
+ if (doSort)
+ ::sSort(sortedColumns);
for (const QString& column : sortedColumns)
items[key] += DbTreeItemFactory::createColumn(column, this);
@@ -681,7 +680,23 @@ void DbTreeModel::restoreExpandedState(const QHash<QString, bool>& expandedState
restoreExpandedState(expandedState, child);
}
-void DbTreeModel::dbConnected(Db* db)
+DbTreeItem* DbTreeModel::findFirstItemOfType(DbTreeItem::Type type, QStandardItem* parentItem)
+{
+ DbTreeItem* child = nullptr;
+ for (int i = 0; i < parentItem->rowCount(); i++)
+ {
+ child = dynamic_cast<DbTreeItem*>(parentItem->child(i));
+ if (child->getType() == type)
+ return child;
+
+ child = findFirstItemOfType(type, child);
+ if (child)
+ return child;
+ }
+ return nullptr;
+}
+
+void DbTreeModel::dbConnected(Db* db, bool expandItem)
{
QStandardItem* item = findItem(DbTreeItem::Type::DB, db);
if (!item)
@@ -690,12 +705,15 @@ void DbTreeModel::dbConnected(Db* db)
return;
}
refreshSchema(db, item);
- treeView->expand(item->index());
- if (CFG_UI.General.ExpandTables.get())
- treeView->expand(item->index().child(0, 0)); // also expand tables
+ if (expandItem)
+ {
+ treeView->expand(item->index());
+ if (CFG_UI.General.ExpandTables.get())
+ treeView->expand(item->model()->index(0, 0, item->index())); // also expand tables
- if (CFG_UI.General.ExpandViews.get())
- treeView->expand(item->index().child(1, 0)); // also expand views
+ if (CFG_UI.General.ExpandViews.get())
+ treeView->expand(item->model()->index(1, 0, item->index())); // also expand views
+ }
}
void DbTreeModel::dbDisconnected(Db* db)
@@ -798,6 +816,11 @@ DbTreeItem *DbTreeModel::findItem(DbTreeItem::Type type, Db* db)
return findItem(root(), type, db);
}
+DbTreeItem* DbTreeModel::findFirstItemOfType(DbTreeItem::Type type)
+{
+ return findFirstItemOfType(type, root());
+}
+
DbTreeItem *DbTreeModel::findItemBySignature(const QString &signature)
{
QStringList parts = signature.split("_");
@@ -953,7 +976,7 @@ bool DbTreeModel::pasteData(const QMimeData* data, int row, int column, const QM
DbTreeItem* dstItem = nullptr;
if (parent.isValid())
{
- QModelIndex idx = parent.child(row, column);
+ QModelIndex idx = index(row, column, parent);
if (idx.isValid())
dstItem = dynamic_cast<DbTreeItem*>(itemFromIndex(idx));
else // drop on top of the parent
@@ -1268,6 +1291,7 @@ void DbTreeModel::dbObjectsMoveFinished(bool success, Db* srcDb, Db* dstDb)
if (!success)
{
interruptableFinished(dbOrganizer);
+ DBTREE->refreshSchema(srcDb);
return;
}