aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dbtree
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
commit1fdc150116cad39aae5c5da407c3312b47a59e3a (patch)
tree123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/guiSQLiteStudio/dbtree
parentfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff)
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dbtree')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp94
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.h8
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitem.cpp10
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitemdelegate.cpp6
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.cpp56
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h10
6 files changed, 115 insertions, 69 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp
index ba8ccc1..85a7047 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp
@@ -26,10 +26,10 @@
#include "windows/editorwindow.h"
#include "uiconfig.h"
#include "themetuner.h"
-#include "dialogs/dbconverterdialog.h"
#include "querygenerator.h"
#include "dialogs/execfromfiledialog.h"
#include "dialogs/fileexecerrorsdialog.h"
+#include "common/compatibility.h"
#include <QApplication>
#include <QClipboard>
#include <QAction>
@@ -44,6 +44,7 @@
#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
+#include <QElapsedTimer>
#include <QtConcurrent/QtConcurrentRun>
CFG_KEYS_DEFINE(DbTree)
@@ -104,6 +105,7 @@ void DbTree::init()
connect(this, &DbTree::updateFileExecProgress, this, &DbTree::setFileExecProgress, Qt::QueuedConnection);
connect(this, &DbTree::fileExecCoverToBeClosed, this, &DbTree::hideFileExecCover, Qt::QueuedConnection);
connect(this, &DbTree::fileExecErrors, this, &DbTree::showFileExecErrors, Qt::QueuedConnection);
+ connect(this, SIGNAL(schemaNeedsRefreshing(Db*)), this, SLOT(refreshSchema(Db*)), Qt::QueuedConnection);
treeModel = new DbTreeModel();
treeModel->setTreeView(ui->treeView);
@@ -144,7 +146,6 @@ void DbTree::createActions()
createAction(DISCONNECT_FROM_DB, ICONS.DATABASE_DISCONNECT, tr("&Disconnect from the database"), this, SLOT(disconnectFromDb()), this);
createAction(IMPORT_INTO_DB, ICONS.IMPORT, tr("Import"), this, SLOT(import()), this);
createAction(EXPORT_DB, ICONS.DATABASE_EXPORT, tr("&Export the database"), this, SLOT(exportDb()), this);
- createAction(CONVERT_DB, ICONS.CONVERT_DB, tr("Con&vert database type"), this, SLOT(convertDb()), this);
createAction(VACUUM_DB, ICONS.VACUUM_DB, tr("Vac&uum"), this, SLOT(vacuumDb()), this);
createAction(INTEGRITY_CHECK, ICONS.INTEGRITY_CHECK, tr("&Integrity check"), this, SLOT(integrityCheck()), this);
createAction(ADD_TABLE, ICONS.TABLE_ADD, tr("Create a &table"), this, SLOT(addTable()), this);
@@ -207,7 +208,7 @@ void DbTree::updateActionStates(const QStandardItem *item)
enabled << DELETE_DB << EDIT_DB;
if (dbTreeItem->getDb()->isOpen())
{
- enabled << DISCONNECT_FROM_DB << ADD_TABLE << ADD_VIEW << IMPORT_INTO_DB << EXPORT_DB << REFRESH_SCHEMA << CONVERT_DB
+ enabled << DISCONNECT_FROM_DB << IMPORT_INTO_DB << EXPORT_DB << REFRESH_SCHEMA
<< VACUUM_DB << INTEGRITY_CHECK;
isDbOpen = true;
}
@@ -340,8 +341,14 @@ void DbTree::updateActionStates(const QStandardItem *item)
}
if (treeModel->rowCount() > 0)
+ {
enabled << SELECT_ALL; // if there's at least 1 item, enable this
+ // Table/view always enabled, as long as there is at least 1 db on the list. #4017
+ if (treeModel->findFirstItemOfType(DbTreeItem::Type::DB))
+ enabled << ADD_TABLE << ADD_VIEW;
+ }
+
enabled << REFRESH_SCHEMAS;
for (int action : actionMap.keys())
@@ -413,7 +420,6 @@ void DbTree::setupActionsForMenu(DbTreeItem* currItem, QMenu* contextMenu)
actions += ActionEntry(REFRESH_SCHEMA);
actions += ActionEntry(IMPORT_INTO_DB);
actions += ActionEntry(EXPORT_DB);
- actions += ActionEntry(CONVERT_DB);
actions += ActionEntry(VACUUM_DB);
actions += ActionEntry(INTEGRITY_CHECK);
actions += ActionEntry(EXEC_SQL_FROM_FILE);
@@ -715,7 +721,7 @@ bool DbTree::areDbTreeItemsValidForItem(QList<DbTreeItem*> srcItems, const DbTre
{DbTreeItem::Type::INDEX, DbTreeItem::Type::INDEXES}
};
- if (!forPasting && srcTypes.toSet().size() == 1 && srcDbs.size() == 1 && dstItem &&
+ if (!forPasting && toSet(srcTypes).size() == 1 && srcDbs.size() == 1 && dstItem &&
*(srcDbs.begin()) == dstItem->getDb() && reorderingTypeToParent[srcTypes.first()] == dstType)
return true;
@@ -794,7 +800,7 @@ Db* DbTree::getSelectedOpenDb()
TableWindow* DbTree::openTable(DbTreeItem* item)
{
- QString database = QString::null; // TODO implement this when named databases (attached) are handled by dbtree.
+ QString database = QString(); // TODO implement this when named databases (attached) are handled by dbtree.
Db* db = item->getDb();
return openTable(db, database, item->text());
}
@@ -807,7 +813,7 @@ TableWindow* DbTree::openTable(Db* db, const QString& database, const QString& t
void DbTree::editIndex(DbTreeItem* item)
{
- //QString database = QString::null; // TODO implement this when named databases (attached) are handled by dbtree.
+ //QString database = QString(); // TODO implement this when named databases (attached) are handled by dbtree.
Db* db = item->getDb();
DbObjectDialogs dialogs(db);
@@ -816,7 +822,7 @@ void DbTree::editIndex(DbTreeItem* item)
ViewWindow* DbTree::openView(DbTreeItem* item)
{
- QString database = QString::null; // TODO implement this when named databases (attached) are handled by dbtree.
+ QString database = QString(); // TODO implement this when named databases (attached) are handled by dbtree.
Db* db = item->getDb();
return openView(db, database, item->text());
}
@@ -827,25 +833,21 @@ ViewWindow* DbTree::openView(Db* db, const QString& database, const QString& vie
return dialogs.editView(database, view);
}
-TableWindow* DbTree::newTable(DbTreeItem* item)
+TableWindow* DbTree::newTable(Db* db)
{
- Db* db = item->getDb();
-
DbObjectDialogs dialogs(db);
return dialogs.addTable();
}
-ViewWindow* DbTree::newView(DbTreeItem* item)
+ViewWindow* DbTree::newView(Db* db)
{
- Db* db = item->getDb();
-
DbObjectDialogs dialogs(db);
return dialogs.addView();
}
void DbTree::editTrigger(DbTreeItem* item)
{
- //QString database = QString::null; // TODO implement this when named databases (attached) are handled by dbtree.
+ //QString database = QString(); // TODO implement this when named databases (attached) are handled by dbtree.
Db* db = item->getDb();
DbObjectDialogs dialogs(db);
@@ -1161,7 +1163,7 @@ void DbTree::editDb()
void DbTree::removeDb()
{
- QList<Db*> dbList = getSelectedDatabases().toList();
+ QList<Db*> dbList = getSelectedDatabases().values();
if (dbList.isEmpty())
return;
@@ -1248,10 +1250,16 @@ void DbTree::addTable()
{
Db* db = getSelectedOpenDb();
if (!db || !db->isValid())
+ {
+ DbTreeItem* item = treeModel->findFirstItemOfType(DbTreeItem::Type::DB);
+ if (item)
+ db = item->getDb();
+ }
+
+ if (!db || !db->isValid())
return;
- DbTreeItem* item = ui->treeView->currentItem();
- newTable(item);
+ newTable(db);
}
void DbTree::editTable()
@@ -1267,7 +1275,7 @@ void DbTree::editTable()
return;
}
- openTable(db, QString::null, table); // TODO put database name when supported
+ openTable(db, QString(), table); // TODO put database name when supported
}
void DbTree::delTable()
@@ -1340,10 +1348,16 @@ void DbTree::addView()
{
Db* db = getSelectedOpenDb();
if (!db || !db->isValid())
+ {
+ DbTreeItem* item = treeModel->findFirstItemOfType(DbTreeItem::Type::DB);
+ if (item)
+ db = item->getDb();
+ }
+
+ if (!db || !db->isValid())
return;
- DbTreeItem* item = ui->treeView->currentItem();
- newView(item);
+ newView(db);
}
void DbTree::editView()
@@ -1463,17 +1477,6 @@ void DbTree::delColumn()
delColumn(item);
}
-void DbTree::convertDb()
-{
- Db* db = getSelectedDb();
- if (!db || !db->isValid())
- return;
-
- DbConverterDialog dialog(this);
- dialog.setDb(db);
- dialog.exec();
-}
-
void DbTree::vacuumDb()
{
Db* db = getSelectedDb();
@@ -1569,11 +1572,10 @@ void DbTree::eraseTableData()
return;
static_qstring(DELETE_SQL, "DELETE FROM %1;");
- Dialect dialect = db->getDialect();
SqlQueryPtr res;
for (const QString& table : tables)
{
- res = db->exec(DELETE_SQL.arg(wrapObjIfNeeded(table, dialect)));
+ res = db->exec(DELETE_SQL.arg(wrapObjIfNeeded(table)));
if (res->isError())
{
notifyError(tr("An error occurred while trying to delete data from table '%1': %2").arg(table, res->getErrorText()));
@@ -1898,7 +1900,7 @@ void DbTree::execFromFileAsync(const QString& path, Db* db, bool ignoreErrors, c
int executed = 0;
bool ok = true;
- QTime timer;
+ QElapsedTimer timer;
timer.start();
QList<QPair<QString, QString>> errors = executeFileQueries(db, stream, executed, attemptedExecutions, ok, ignoreErrors, fileSize);
int millis = timer.elapsed();
@@ -1935,8 +1937,11 @@ QList<QPair<QString, QString>> DbTree::executeFileQueries(Db* db, QTextStream& s
}
}
- if (sql.trimmed().isEmpty())
+ if (shouldSkipQueryFromFileExecution(sql))
+ {
+ sql.clear();;
continue;
+ }
results = db->exec(sql);
attemptedExecutions++;
@@ -1961,6 +1966,18 @@ QList<QPair<QString, QString>> DbTree::executeFileQueries(Db* db, QTextStream& s
return errors;
}
+bool DbTree::shouldSkipQueryFromFileExecution(const QString& sql)
+{
+ if (sql.trimmed().isEmpty())
+ return true;
+
+ QString upper = sql.toUpper().trimmed().split("\n").last().trimmed();
+ return (upper.startsWith("BEGIN") ||
+ upper.startsWith("COMMIT") ||
+ upper.startsWith("ROLLBACK") ||
+ upper.startsWith("END"));
+}
+
void DbTree::handleFileQueryExecution(Db* db, int executed, int attemptedExecutions, bool ok, bool ignoreErrors, int millis)
{
bool doCommit = ok ? true : ignoreErrors;
@@ -1968,17 +1985,20 @@ void DbTree::handleFileQueryExecution(Db* db, int executed, int attemptedExecuti
{
if (!db->commit())
{
- db->rollback();
notifyError(tr("Could not execute SQL, because application has failed to commit the transaction: %1").arg(db->getErrorText()));
+ db->rollback();
}
else if (!ok) // committed with errors
{
notifyInfo(tr("Finished executing %1 queries in %2 seconds. %3 were not executed due to errors.")
.arg(executed).arg(millis / 1000.0).arg(attemptedExecutions - executed));
+
+ emit schemaNeedsRefreshing(db);
}
else
{
notifyInfo(tr("Finished executing %1 queries in %2 seconds.").arg(executed).arg(millis / 1000.0));
+ emit schemaNeedsRefreshing(db);
}
}
else
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.h b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.h
index f72ebda..62ef0df 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.h
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.h
@@ -60,7 +60,6 @@ class GUI_API_EXPORT DbTree : public QDockWidget, public ExtActionContainer
DISCONNECT_FROM_DB,
IMPORT_INTO_DB,
EXPORT_DB,
- CONVERT_DB,
VACUUM_DB,
INTEGRITY_CHECK,
ADD_TABLE,
@@ -133,10 +132,10 @@ class GUI_API_EXPORT DbTree : public QDockWidget, public ExtActionContainer
void setActionEnabled(int action, bool enabled);
TableWindow* openTable(DbTreeItem* item);
TableWindow* openTable(Db* db, const QString& database, const QString& table);
- TableWindow* newTable(DbTreeItem* item);
+ TableWindow* newTable(Db* db);
ViewWindow* openView(DbTreeItem* item);
ViewWindow* openView(Db* db, const QString& database, const QString& view);
- ViewWindow* newView(DbTreeItem* item);
+ ViewWindow* newView(Db* db);
void editIndex(DbTreeItem* item);
void editTrigger(DbTreeItem* item);
void delSelectedObject();
@@ -156,6 +155,7 @@ class GUI_API_EXPORT DbTree : public QDockWidget, public ExtActionContainer
bool execQueryFromFile(Db* db, const QString& sql);
void handleFileQueryExecution(Db* db, int executed, int attemptedExecutions, bool ok, bool ignoreErrors, int millis);
QList<QPair<QString, QString>> executeFileQueries(Db* db, QTextStream& stream, int& executed, int& attemptedExecutions, bool& ok, bool ignoreErrors, qint64 fileSize);
+ bool shouldSkipQueryFromFileExecution(const QString& sql);
static bool areDbTreeItemsValidForItem(QList<DbTreeItem*> srcItems, const DbTreeItem* dstItem, bool forPasting = false);
static bool areUrlsValidForItem(const QList<QUrl>& srcUrls, const DbTreeItem* dstItem);
@@ -210,7 +210,6 @@ class GUI_API_EXPORT DbTree : public QDockWidget, public ExtActionContainer
void addColumn();
void editColumn();
void delColumn();
- void convertDb();
void vacuumDb();
void integrityCheck();
void createSimilarTable();
@@ -241,6 +240,7 @@ class GUI_API_EXPORT DbTree : public QDockWidget, public ExtActionContainer
void updateFileExecProgress(int value);
void fileExecCoverToBeClosed();
void fileExecErrors(const QList<QPair<QString, QString>>& errors, bool rolledBack);
+ void schemaNeedsRefreshing(Db* db);
};
int qHash(DbTree::Action action);
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitem.cpp b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitem.cpp
index ead5e3d..6514aa8 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitem.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitem.cpp
@@ -85,7 +85,7 @@ QString DbTreeItem::getTable() const
{
const DbTreeItem* item = getParentItem(Type::TABLE);
if (!item)
- return QString::null;
+ return QString();
return item->text();
}
@@ -93,7 +93,7 @@ QString DbTreeItem::getTable() const
QString DbTreeItem::getColumn() const
{
if (getType() != Type::COLUMN)
- return QString::null;
+ return QString();
return text();
}
@@ -102,7 +102,7 @@ QString DbTreeItem::getIndex() const
{
const DbTreeItem* item = getParentItem(Type::INDEX);
if (!item)
- return QString::null;
+ return QString();
return item->text();
}
@@ -111,7 +111,7 @@ QString DbTreeItem::getTrigger() const
{
const DbTreeItem* item = getParentItem(Type::TRIGGER);
if (!item)
- return QString::null;
+ return QString();
return item->text();
}
@@ -120,7 +120,7 @@ QString DbTreeItem::getView() const
{
const DbTreeItem* item = getParentItem(Type::VIEW);
if (!item)
- return QString::null;
+ return QString();
return item->text();
}
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitemdelegate.cpp b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitemdelegate.cpp
index ef691d2..552bd91 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitemdelegate.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreeitemdelegate.cpp
@@ -133,7 +133,7 @@ void DbTreeItemDelegate::paintSystemIndexLabel(QPainter* painter, const QStyleOp
if (!db || !db->isValid())
return;
- if (!isSystemIndex(item->text(), db->getDialect()))
+ if (!isSystemIndex(item->text()))
return;
paintLabel(painter, option, index, item, tr("(system index)", "database tree label"));
@@ -147,7 +147,7 @@ void DbTreeItemDelegate::paintLabel(QPainter *painter, const QStyleOptionViewIte
painter->save();
// Colors
- painter->setPen(CFG_UI.Colors.DbTreeLabelsFg.get());
+ painter->setPen(QApplication::style()->standardPalette().link().color());
// Font
opt.font = CFG_UI.Fonts.DbTreeLabel.get();
@@ -155,7 +155,7 @@ void DbTreeItemDelegate::paintLabel(QPainter *painter, const QStyleOptionViewIte
painter->setFont(opt.font);
// Coords
- int x = option.rect.x() + option.fontMetrics.width(item->text()) + 15 + option.decorationSize.width();
+ int x = option.rect.x() + option.fontMetrics.horizontalAdvance(item->text()) + 15 + option.decorationSize.width();
int y = opt.rect.y() + (opt.rect.height() - opt.fontMetrics.descent() - opt.fontMetrics.ascent()) / 2 + opt.fontMetrics.ascent();
// Paint
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;
}
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h
index 9ba0d82..86dc8a6 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h
+++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h
@@ -27,6 +27,7 @@ class GUI_API_EXPORT DbTreeModel : public QStandardItemModel
void connectDbManagerSignals();
DbTreeItem* findItem(DbTreeItem::Type type, const QString &name);
DbTreeItem* findItem(DbTreeItem::Type type, Db* db);
+ DbTreeItem* findFirstItemOfType(DbTreeItem::Type type);
DbTreeItem* findItemBySignature(const QString& signature);
QList<DbTreeItem*> findItems(DbTreeItem::Type type);
void move(QStandardItem* itemToMove, QStandardItem* newParentItem, int newRow = -1);
@@ -69,14 +70,15 @@ class GUI_API_EXPORT DbTreeModel : public QStandardItemModel
void collectExpandedState(QHash<QString, bool>& state, QStandardItem* parentItem = nullptr);
QStandardItem* refreshSchemaDb(Db* db);
QList<QStandardItem*> refreshSchemaTables(const QStringList &tables, const QStringList& virtualTables, bool sort);
- StrHash<QList<QStandardItem*> > refreshSchemaTableColumns(const StrHash<QStringList>& columns);
- StrHash<QList<QStandardItem*> > refreshSchemaIndexes(const StrHash<QStringList>& indexes, bool sort);
- StrHash<QList<QStandardItem*> > refreshSchemaTriggers(const StrHash<QStringList>& triggers, bool sort);
+ StrHash<QList<QStandardItem*>> refreshSchemaTableColumns(const StrHash<QStringList>& columns);
+ StrHash<QList<QStandardItem*>> refreshSchemaIndexes(const StrHash<QStringList>& indexes, bool sort);
+ StrHash<QList<QStandardItem*>> refreshSchemaTriggers(const StrHash<QStringList>& triggers, bool sort);
QList<QStandardItem*> refreshSchemaViews(const QStringList &views, bool sort);
void populateChildItemsWithDb(QStandardItem* parentItem, Db* db);
void refreshSchemaBuild(QStandardItem* dbItem, QList<QStandardItem*> tables, StrHash<QList<QStandardItem*> > indexes,
StrHash<QList<QStandardItem*> > triggers, QList<QStandardItem*> views, StrHash<QList<QStandardItem*> > allTableColumns);
void restoreExpandedState(const QHash<QString, bool>& expandedState, QStandardItem* parentItem);
+ DbTreeItem* findFirstItemOfType(DbTreeItem::Type type, QStandardItem* parentItem);
QString getToolTip(DbTreeItem *item) const;
QString getDbToolTip(DbTreeItem *item) const;
QString getTableToolTip(DbTreeItem *item) const;
@@ -111,7 +113,7 @@ class GUI_API_EXPORT DbTreeModel : public QStandardItemModel
void dbAdded(Db* db);
void dbUpdated(const QString &oldName, Db* db);
void dbRemoved(Db* db);
- void dbConnected(Db* db);
+ void dbConnected(Db* db, bool expandItem = true);
void dbDisconnected(Db* db);
void dbUnloaded(Db* db);
void dbLoaded(Db* db);