Skip to content

Commit 012ad92

Browse files
committed
Fix drag & drop of tables onto the structure view
When dragging and dropping a table from one instance of the application to the other, the tree structure representing the database was broken. We would show the 'Browsables' and 'All' nodes at the top level instead of the child nodes of the 'All' node. This happened because after dropping a table, we would reload the database structure and rebuild the tree structure but didn't notify the tree view in the main window about the update. This is fixed by this commit, so the main window's widgets are always notified about the new tree structure. See issue #1288.
1 parent 39a5460 commit 012ad92

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/DbStructureModel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void DbStructureModel::reloadData()
138138
if(!m_db.isOpen())
139139
{
140140
endResetModel();
141+
emit structureUpdated();
141142
return;
142143
}
143144

@@ -179,6 +180,7 @@ void DbStructureModel::reloadData()
179180

180181
// Refresh the view
181182
endResetModel();
183+
emit structureUpdated();
182184
}
183185

184186
QStringList DbStructureModel::mimeTypes() const
@@ -263,7 +265,6 @@ bool DbStructureModel::dropMimeData(const QMimeData* data, Qt::DropAction action
263265
if(m_db.executeMultiSQL(d, true, true))
264266
{
265267
m_db.updateSchema();
266-
reloadData();
267268
return true;
268269
} else {
269270
QMessageBox::warning(nullptr, QApplication::applicationName(), m_db.lastError());

src/DbStructureModel.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class DbStructureModel : public QAbstractItemModel
1515
explicit DbStructureModel(DBBrowserDB& db, QObject* parent = nullptr);
1616
~DbStructureModel();
1717

18-
void reloadData();
19-
2018
QVariant data(const QModelIndex& index, int role) const;
2119
Qt::ItemFlags flags(const QModelIndex& index) const;
2220
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
@@ -38,6 +36,12 @@ class DbStructureModel : public QAbstractItemModel
3836
ColumnSchema,
3937
};
4038

39+
public slots:
40+
void reloadData();
41+
42+
signals:
43+
void structureUpdated();
44+
4145
private:
4246
DBBrowserDB& m_db;
4347
QTreeWidgetItem* rootItem;

src/MainWindow.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ void MainWindow::init()
9292
// Connect SQL logging and database state setting to main window
9393
connect(&db, SIGNAL(dbChanged(bool)), this, SLOT(dbState(bool)));
9494
connect(&db, SIGNAL(sqlExecuted(QString, int)), this, SLOT(logSql(QString,int)));
95-
connect(&db, SIGNAL(structureUpdated()), this, SLOT(populateStructure()));
9695
connect(&db, &DBBrowserDB::requestCollation, this, &MainWindow::requestCollation);
9796

9897
// Set the validator for the goto line edit
@@ -107,6 +106,11 @@ void MainWindow::init()
107106

108107
// Set up DB structure tab
109108
dbStructureModel = new DbStructureModel(db, this);
109+
connect(&db, &DBBrowserDB::structureUpdated, [this]() {
110+
QString old_table = ui->comboBrowseTable->currentText();
111+
dbStructureModel->reloadData();
112+
populateStructure(old_table);
113+
});
110114
ui->dbTreeWidget->setModel(dbStructureModel);
111115
ui->dbTreeWidget->setColumnWidth(DbStructureModel::ColumnName, 300);
112116
ui->dbTreeWidget->setColumnHidden(DbStructureModel::ColumnObjectType, true);
@@ -396,12 +400,9 @@ void MainWindow::fileNew()
396400
}
397401
}
398402

399-
void MainWindow::populateStructure()
403+
void MainWindow::populateStructure(const QString& old_table)
400404
{
401-
QString old_table = ui->comboBrowseTable->currentText();
402-
403405
// Refresh the structure tab
404-
dbStructureModel->reloadData();
405406
ui->dbTreeWidget->setRootIndex(dbStructureModel->index(1, 0)); // Show the 'All' part of the db structure
406407
ui->dbTreeWidget->expandToDepth(0);
407408
ui->treeSchemaDock->setRootIndex(dbStructureModel->index(1, 0)); // Show the 'All' part of the db structure
@@ -1970,7 +1971,7 @@ void MainWindow::reloadSettings()
19701971
loadExtensionsFromSettings();
19711972

19721973
// Refresh view
1973-
populateStructure();
1974+
dbStructureModel->reloadData();
19741975
populateTable();
19751976

19761977
// Hide or show the remote dock as needed

src/MainWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public slots:
213213
void refresh();
214214
void jumpToRow(const sqlb::ObjectIdentifier& table, QString column, const QByteArray& value);
215215
void switchToBrowseDataTab(QString tableToBrowse = QString());
216-
void populateStructure();
216+
void populateStructure(const QString& old_table = QString());
217217

218218
private slots:
219219
void createTreeContextMenu(const QPoint & qPoint);

0 commit comments

Comments
 (0)