All the detail tabs on the TablePage now update when the sort order

of the table list changes.
This commit is contained in:
eelke 2018-10-21 13:47:38 +02:00
parent d4d8316917
commit 1ae9a1151a
5 changed files with 61 additions and 26 deletions

View file

@ -19,7 +19,17 @@ PropertiesPage::PropertiesPage(QWidget *parent) : QSplitter(parent)
auto item_delegate = new PgLabItemDelegate(this);
m_tableView->setItemDelegate(item_delegate);
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
}
//property_model->setSourceModel(m_tablesModel);
void PropertiesPage::setSourceModel(QAbstractItemModel *model)
{
m_propertyProxyModel->setSourceModel(model);
}
void PropertiesPage::setActiveRow(const QModelIndex &row)
{
m_propertyProxyModel->setActiveRow(row);
}

View file

@ -7,6 +7,7 @@ class QTableView;
class SqlCodePreview;
class PgDatabaseCatalog;
class PropertyProxyModel;
class QAbstractItemModel;
class PropertiesPage : public QSplitter
{
@ -14,9 +15,16 @@ class PropertiesPage : public QSplitter
public:
explicit PropertiesPage(QWidget *parent = nullptr);
void setSourceModel(QAbstractItemModel *model);
signals:
public slots:
/** Updates the model (and view) to show the values for row
*
* The column part of the index is not used QModelIndex is used to make is eacy to connect to
* QItemSelectionModel::currentRowChanged
*/
void setActiveRow(const QModelIndex &row);
private:
QTableView *m_tableView = nullptr;

View file

@ -26,6 +26,7 @@ TablesPage::TablesPage(MainWindow *parent)
{
ui->setupUi(this);
// WARNING delegates should NOT be shared!!!
auto pglab_delegate = new PgLabItemDelegate(this);
auto icon_delegate = new IconColumnDelegate(this);
@ -35,6 +36,7 @@ TablesPage::TablesPage(MainWindow *parent)
ui->tableListTable->setItemDelegate(pglab_delegate);
ui->tableListTable->setSortingEnabled(true);
ui->tableListTable->sortByColumn(0, Qt::AscendingOrder);
ui->tableListTable->setSelectionBehavior(QAbstractItemView::SelectRows);
// Columns
SetTableViewDefault(ui->columnsTable);
@ -63,11 +65,14 @@ TablesPage::TablesPage(MainWindow *parent)
// Connect signals
// ---------------
// Table selection
// connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged,
// property_model, &PropertyProxyModel::setActiveRow);
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&TablesPage::tableListTable_currentRowChanged);
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
this, &TablesPage::tableListTable_layoutChanged);
//layoutChanged(const QList<QPersistentModelIndex> &parents = ..., QAbstractItemModel::LayoutChangeHint hint = ...)
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TablesPage::constraintsTable_selectionChanged);
connect(ui->constraintsTable->model(), &QAbstractItemModel::modelReset, this,
@ -81,9 +86,14 @@ TablesPage::TablesPage(MainWindow *parent)
&TablesPage::indexesTable_modelReset);
// Non designer based code
// - Properties page
m_propertiesPage = new PropertiesPage(this);
m_propertiesPage->setSourceModel(m_tablesModel);
m_propertiesTab = addDetailTab(m_propertiesPage);
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged,
m_propertiesPage, &PropertiesPage::setActiveRow);
// - Trigger page
m_triggerPage = new TriggerPage(this);
m_triggerTab = addDetailTab(m_triggerPage);
@ -122,7 +132,6 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
ui->tableListTable->resizeColumnsToContents();
m_triggerPage->setCatalog(cat);
// m_namespaceFilterWidget->init(cat->namespaces());
auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
highlighter->setTypes(*cat->types());
@ -130,36 +139,39 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
highlighter->setTypes(*cat->types());
}
void TablesPage::tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.row() != previous.row()) {
PgClass table = m_tablesModel->getTable(current.row());
m_columnsModel->setData(m_catalog, table);
ui->columnsTable->resizeColumnsToContents();
m_constraintModel->setData(m_catalog, table);
ui->constraintsTable->resizeColumnsToContents();
ui->constraintsTable->selectionModel()->reset();
m_indexModel->setData(m_catalog, table);
ui->indexesTable->resizeColumnsToContents();
m_triggerPage->setFilter(table);
selectedTableChanged(table);
}
}
//void TablesPage::constraintsTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
//{
// if (current.row() != previous.row()) {
//// QString drop_definition = m_constraintModel->dropDefinition(current.row());
//// QString create_definition = m_constraintModel->createDefinition(current.row());
// const PgConstraint& constraint = m_constraintModel->constraint(current.row());
// QString drop = getDropConstraintDefinition(*m_catalog, constraint);
// QString add = getConstraintDefinition(*m_catalog, constraint);
// ui->constraintSqlEdit->setPlainText(drop % QString::fromUtf16(u"\n") % add);
// }
//}
void TablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint )
{
auto&& index = ui->tableListTable->selectionModel()->currentIndex();
PgClass table = m_tablesModel->getTable(index.row());
selectedTableChanged(table);
}
void TablesPage::selectedTableChanged(const PgClass & table)
{
m_columnsModel->setData(m_catalog, table);
ui->columnsTable->resizeColumnsToContents();
m_constraintModel->setData(m_catalog, table);
ui->constraintsTable->resizeColumnsToContents();
ui->constraintsTable->selectionModel()->reset();
m_indexModel->setData(m_catalog, table);
ui->indexesTable->resizeColumnsToContents();
m_triggerPage->setFilter(table);
}
void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{

View file

@ -18,6 +18,7 @@ class IndexModel;
class MainWindow;
class PropertiesPage;
class TriggerPage;
class PgClass;
class TablesPage : public QWidget
{
@ -44,9 +45,12 @@ private:
void retranslateUi(bool all = true);
QWidget* addDetailTab(QWidget *contents);
void selectedTableChanged(const PgClass & table);
private slots:
void tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void tableListTable_layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
// void constraintsTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
void constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void constraintsTable_modelReset();

View file

@ -26,6 +26,7 @@ TriggerPage::TriggerPage(QWidget *parent)
m_sortFilterProxy->setSourceModel(m_model);
m_tableView->setModel(m_sortFilterProxy);
m_tableView->setSortingEnabled(true);
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
auto item_delegate = new PgLabItemDelegate(this);
m_tableView->setItemDelegate(item_delegate);