mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
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.
This commit is contained in:
@@ -138,6 +138,7 @@ void DbStructureModel::reloadData()
|
||||
if(!m_db.isOpen())
|
||||
{
|
||||
endResetModel();
|
||||
emit structureUpdated();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -179,6 +180,7 @@ void DbStructureModel::reloadData()
|
||||
|
||||
// Refresh the view
|
||||
endResetModel();
|
||||
emit structureUpdated();
|
||||
}
|
||||
|
||||
QStringList DbStructureModel::mimeTypes() const
|
||||
@@ -263,7 +265,6 @@ bool DbStructureModel::dropMimeData(const QMimeData* data, Qt::DropAction action
|
||||
if(m_db.executeMultiSQL(d, true, true))
|
||||
{
|
||||
m_db.updateSchema();
|
||||
reloadData();
|
||||
return true;
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), m_db.lastError());
|
||||
|
||||
@@ -15,8 +15,6 @@ public:
|
||||
explicit DbStructureModel(DBBrowserDB& db, QObject* parent = nullptr);
|
||||
~DbStructureModel();
|
||||
|
||||
void reloadData();
|
||||
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
@@ -38,6 +36,12 @@ public:
|
||||
ColumnSchema,
|
||||
};
|
||||
|
||||
public slots:
|
||||
void reloadData();
|
||||
|
||||
signals:
|
||||
void structureUpdated();
|
||||
|
||||
private:
|
||||
DBBrowserDB& m_db;
|
||||
QTreeWidgetItem* rootItem;
|
||||
|
||||
@@ -92,7 +92,6 @@ void MainWindow::init()
|
||||
// Connect SQL logging and database state setting to main window
|
||||
connect(&db, SIGNAL(dbChanged(bool)), this, SLOT(dbState(bool)));
|
||||
connect(&db, SIGNAL(sqlExecuted(QString, int)), this, SLOT(logSql(QString,int)));
|
||||
connect(&db, SIGNAL(structureUpdated()), this, SLOT(populateStructure()));
|
||||
connect(&db, &DBBrowserDB::requestCollation, this, &MainWindow::requestCollation);
|
||||
|
||||
// Set the validator for the goto line edit
|
||||
@@ -107,6 +106,11 @@ void MainWindow::init()
|
||||
|
||||
// Set up DB structure tab
|
||||
dbStructureModel = new DbStructureModel(db, this);
|
||||
connect(&db, &DBBrowserDB::structureUpdated, [this]() {
|
||||
QString old_table = ui->comboBrowseTable->currentText();
|
||||
dbStructureModel->reloadData();
|
||||
populateStructure(old_table);
|
||||
});
|
||||
ui->dbTreeWidget->setModel(dbStructureModel);
|
||||
ui->dbTreeWidget->setColumnWidth(DbStructureModel::ColumnName, 300);
|
||||
ui->dbTreeWidget->setColumnHidden(DbStructureModel::ColumnObjectType, true);
|
||||
@@ -396,12 +400,9 @@ void MainWindow::fileNew()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::populateStructure()
|
||||
void MainWindow::populateStructure(const QString& old_table)
|
||||
{
|
||||
QString old_table = ui->comboBrowseTable->currentText();
|
||||
|
||||
// Refresh the structure tab
|
||||
dbStructureModel->reloadData();
|
||||
ui->dbTreeWidget->setRootIndex(dbStructureModel->index(1, 0)); // Show the 'All' part of the db structure
|
||||
ui->dbTreeWidget->expandToDepth(0);
|
||||
ui->treeSchemaDock->setRootIndex(dbStructureModel->index(1, 0)); // Show the 'All' part of the db structure
|
||||
@@ -1970,7 +1971,7 @@ void MainWindow::reloadSettings()
|
||||
loadExtensionsFromSettings();
|
||||
|
||||
// Refresh view
|
||||
populateStructure();
|
||||
dbStructureModel->reloadData();
|
||||
populateTable();
|
||||
|
||||
// Hide or show the remote dock as needed
|
||||
|
||||
@@ -213,7 +213,7 @@ public slots:
|
||||
void refresh();
|
||||
void jumpToRow(const sqlb::ObjectIdentifier& table, QString column, const QByteArray& value);
|
||||
void switchToBrowseDataTab(QString tableToBrowse = QString());
|
||||
void populateStructure();
|
||||
void populateStructure(const QString& old_table = QString());
|
||||
|
||||
private slots:
|
||||
void createTreeContextMenu(const QPoint & qPoint);
|
||||
|
||||
Reference in New Issue
Block a user