fix: the source views for constraints and indexes are now cleared when the

model is reset as this will clear all selections.

Unfortunatly the selection model does not trigger a selectionChanged when
the model is reset.

Close #16
This commit is contained in:
eelke 2018-08-05 11:57:27 +02:00
parent f1020ac56e
commit 7c4f1a4752
4 changed files with 23 additions and 5 deletions

View file

@ -321,7 +321,7 @@ void MainWindow::addPage(PlgPage* page, QString caption)
//addToolBarButtonsForPage(page);
}
void MainWindow::removePage(PlgPage *page)
void MainWindow::removePage(PlgPage *)
{
}

View file

@ -56,7 +56,7 @@ TablesPage::TablesPage(MainWindow *parent)
//m_namespaceFilterWidget = new NamespaceFilterWidget(this);
//ui->verticalLayoutTableView->addWidget(m_namespaceFilterWidget);
// Table selection
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&TablesPage::tableListTable_currentRowChanged);
@ -65,9 +65,15 @@ TablesPage::TablesPage(MainWindow *parent)
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TablesPage::constraintsTable_selectionChanged);
connect(ui->constraintsTable->model(), &QAbstractItemModel::modelReset, this,
&TablesPage::constraintsTable_modelReset);
// React to changes in de selected indexes, does not trigger when model is reset
connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TablesPage::indexesTable_selectionChanged);
// Capture model reset independently
connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this,
&TablesPage::indexesTable_modelReset);
}
@ -122,7 +128,7 @@ void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selec
{
const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes();
boost::container::flat_set<int> rijen;
for (const auto e : indexes)
for (const auto &e : indexes)
rijen.insert(e.row());
QString drops;
@ -135,11 +141,16 @@ void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selec
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
}
void TablesPage::constraintsTable_modelReset()
{
ui->constraintSqlEdit->clear();
}
void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{
const auto indexes = ui->indexesTable->selectionModel()->selectedIndexes();
boost::container::flat_set<int> rijen;
for (const auto e : indexes)
for (const auto &e : indexes)
rijen.insert(e.row());
QString drops;
@ -153,6 +164,11 @@ void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected*
}
void TablesPage::indexesTable_modelReset()
{
ui->indexSqlEdit->clear();
}
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
{
PgClass table = m_tablesModel->getTable(index.row());

View file

@ -41,7 +41,9 @@ private slots:
void tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
// void constraintsTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void constraintsTable_modelReset();
void indexesTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void indexesTable_modelReset();
void on_tableListTable_doubleClicked(const QModelIndex &index);
};

View file

@ -38,7 +38,7 @@
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="columnsTab">
<attribute name="title">