Collection of small fixes and improvements

- Selections stay clearly visible when focus changes to other widget
- Autoresize columns
- Table properties view now correctly allows selection in both columns and draws selection correctly
- Tables can be sorted again and now by any column
This commit is contained in:
eelke 2019-02-09 14:59:33 +01:00
parent 3fb88edab2
commit 3fdd42ffb2
13 changed files with 56 additions and 41 deletions

View file

@ -1,16 +1,18 @@
#include "ColumnPage.h" #include "ColumnPage.h"
#include "ResultTableModelUtil.h"
#include "UserConfiguration.h"
#include "PgLabTableView.h"
#include "catalog/PgClass.h"
#include "SqlCodePreview.h"
#include "ColumnTableModel.h" #include "ColumnTableModel.h"
#include "CustomFilterSortModel.h" #include "CustomFilterSortModel.h"
#include "CustomDataRole.h" #include "CustomDataRole.h"
#include "PgLabItemDelegate.h" #include "PgLabTableView.h"
#include "ResultTableModelUtil.h"
#include "SqlCodePreview.h"
//#include "PgLabItemDelegate.h"
#include "SqlFormattingUtils.h"
#include "UserConfiguration.h"
#include "catalog/PgClass.h"
#include <QSortFilterProxyModel>
#include <QStringBuilder> #include <QStringBuilder>
#include <unordered_set> #include <unordered_set>
#include "SqlFormattingUtils.h"
ColumnPage::ColumnPage(QWidget *parent) ColumnPage::ColumnPage(QWidget *parent)
: QSplitter(Qt::Vertical, parent) : QSplitter(Qt::Vertical, parent)
@ -21,7 +23,7 @@ ColumnPage::ColumnPage(QWidget *parent)
addWidget(m_definitionView); addWidget(m_definitionView);
m_columnModel = new ColumnTableModel(this); m_columnModel = new ColumnTableModel(this);
m_sortFilterProxy = new CustomFilterSortModel(this); m_sortFilterProxy = new QSortFilterProxyModel(this);
m_sortFilterProxy->setSourceModel(m_columnModel); m_sortFilterProxy->setSourceModel(m_columnModel);
m_tableView->setModel(m_sortFilterProxy); m_tableView->setModel(m_sortFilterProxy);
m_tableView->setSortingEnabled(true); m_tableView->setSortingEnabled(true);
@ -39,13 +41,9 @@ void ColumnPage::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std
m_columnModel->setData(cat, cls); m_columnModel->setData(cat, cls);
m_Class = cls; m_Class = cls;
m_tableView->resizeColumnsToContents(); m_tableView->resizeColumnsToContents();
m_definitionView->setPlainText("");
} }
//void ColumnPage::setFilter(const std::optional<PgClass> &cls)
//{
// m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue);
//}
void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{ {
auto&& indexes = m_tableView->selectionModel()->selectedIndexes(); auto&& indexes = m_tableView->selectionModel()->selectedIndexes();

View file

@ -11,7 +11,7 @@ class PgLabTableView;
class SqlCodePreview; class SqlCodePreview;
class PgDatabaseCatalog; class PgDatabaseCatalog;
class ColumnTableModel; class ColumnTableModel;
class CustomFilterSortModel; class QSortFilterProxyModel;
class QItemSelection; class QItemSelection;
class QAbstractItemModel; class QAbstractItemModel;
@ -31,7 +31,7 @@ private:
PgLabTableView *m_tableView = nullptr; PgLabTableView *m_tableView = nullptr;
SqlCodePreview *m_definitionView = nullptr; SqlCodePreview *m_definitionView = nullptr;
ColumnTableModel *m_columnModel = nullptr; ColumnTableModel *m_columnModel = nullptr;
CustomFilterSortModel *m_sortFilterProxy = nullptr; QSortFilterProxyModel *m_sortFilterProxy = nullptr;
std::shared_ptr<const PgDatabaseCatalog> m_catalog; std::shared_ptr<const PgDatabaseCatalog> m_catalog;
std::optional<PgClass> m_Class; std::optional<PgClass> m_Class;

View file

@ -1,6 +1,7 @@
#include "PgLabTableView.h" #include "PgLabTableView.h"
#include "PgLabItemDelegate.h" #include "PgLabItemDelegate.h"
#include <QHeaderView> #include <QHeaderView>
#include <QSortFilterProxyModel>
PgLabTableView::PgLabTableView(QWidget *parent) PgLabTableView::PgLabTableView(QWidget *parent)
: QTableView(parent) : QTableView(parent)
@ -9,7 +10,13 @@ PgLabTableView::PgLabTableView(QWidget *parent)
setItemDelegate(new PgLabItemDelegate(this)); setItemDelegate(new PgLabItemDelegate(this));
setWordWrap(false); setWordWrap(false);
auto pal = palette();
pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight));
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText));
setPalette(pal);
auto vertical_header = verticalHeader(); auto vertical_header = verticalHeader();
vertical_header->setMinimumSectionSize(16); vertical_header->setMinimumSectionSize(16);
vertical_header->setDefaultSectionSize(20); vertical_header->setDefaultSectionSize(20);
} }

View file

@ -3,10 +3,13 @@
#include <QTableView> #include <QTableView>
class QSortFilterProxyModel;
class PgLabTableView : public QTableView { class PgLabTableView : public QTableView {
Q_OBJECT Q_OBJECT
public: public:
explicit PgLabTableView(QWidget *parent = nullptr); explicit PgLabTableView(QWidget *parent = nullptr);
}; };
#endif // PGLABTABLEVIEW_H #endif // PGLABTABLEVIEW_H

View file

@ -3,14 +3,13 @@
#include "PropertyProxyModel.h" #include "PropertyProxyModel.h"
#include "ResultTableModelUtil.h" #include "ResultTableModelUtil.h"
#include "SqlCodePreview.h" #include "SqlCodePreview.h"
#include <QTableView> #include "PgLabTableView.h"
PropertiesPage::PropertiesPage(QWidget *parent) : QSplitter(parent) PropertiesPage::PropertiesPage(QWidget *parent) : QSplitter(parent)
{ {
m_tableView = new QTableView(this); m_tableView = new PgLabTableView(this);
// m_definitionView = new SqlCodePreview(this);
addWidget(m_tableView); addWidget(m_tableView);
// addWidget(m_definitionView);
SetTableViewDefault(m_tableView); SetTableViewDefault(m_tableView);
@ -32,4 +31,5 @@ void PropertiesPage::setSourceModel(QAbstractItemModel *model)
void PropertiesPage::setActiveRow(const QModelIndex &row) void PropertiesPage::setActiveRow(const QModelIndex &row)
{ {
m_propertyProxyModel->setActiveRow(row); m_propertyProxyModel->setActiveRow(row);
m_tableView->resizeColumnsToContents();
} }

View file

@ -3,21 +3,19 @@
#include <QSplitter> #include <QSplitter>
class QTableView;
class SqlCodePreview; class SqlCodePreview;
class PgDatabaseCatalog; class PgDatabaseCatalog;
class PropertyProxyModel; class PropertyProxyModel;
class PgLabTableView;
class QAbstractItemModel; class QAbstractItemModel;
class PropertiesPage : public QSplitter class PropertiesPage : public QSplitter {
{
Q_OBJECT Q_OBJECT
public: public:
explicit PropertiesPage(QWidget *parent = nullptr); explicit PropertiesPage(QWidget *parent = nullptr);
void setSourceModel(QAbstractItemModel *model); void setSourceModel(QAbstractItemModel *model);
signals: signals:
public slots: public slots:
/** Updates the model (and view) to show the values for row /** Updates the model (and view) to show the values for row
* *
@ -27,8 +25,7 @@ public slots:
void setActiveRow(const QModelIndex &row); void setActiveRow(const QModelIndex &row);
private: private:
QTableView *m_tableView = nullptr; PgLabTableView *m_tableView = nullptr;
// SqlCodePreview *m_definitionView = nullptr;
PropertyProxyModel *m_propertyProxyModel = nullptr; PropertyProxyModel *m_propertyProxyModel = nullptr;
}; };

View file

@ -102,3 +102,8 @@ void PropertyProxyModel::setActiveRow(const QModelIndex &row)
activeRow = row.isValid() ? row.row() : -1; activeRow = row.isValid() ? row.row() : -1;
emit dataChanged(index(0, valueColumn), index(rowCount(QModelIndex()), valueColumn), QVector<int>() << Qt::DisplayRole); emit dataChanged(index(0, valueColumn), index(rowCount(QModelIndex()), valueColumn), QVector<int>() << Qt::DisplayRole);
} }
Qt::ItemFlags PropertyProxyModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}

View file

@ -7,14 +7,15 @@ class PropertyProxyModel : public QIdentityProxyModel {
Q_OBJECT Q_OBJECT
public: public:
PropertyProxyModel(QObject * parent = nullptr); PropertyProxyModel(QObject * parent = nullptr);
QModelIndex mapToSource(const QModelIndex &proxyIndex) const; QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QVariant data(const QModelIndex &proxyIndex, int role) const; QVariant data(const QModelIndex &proxyIndex, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
public Q_SLOTS: public Q_SLOTS:
/** Updates the model (and view) to show the values for row /** Updates the model (and view) to show the values for row

View file

@ -57,6 +57,7 @@ void CatalogFunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> c
{ {
m_catalog = cat; m_catalog = cat;
m_model->setCatalog(cat); m_model->setCatalog(cat);
m_functionTable->resizeColumnsToContents();
} }
void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous) void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)

View file

@ -12,7 +12,6 @@ CatalogIndexPage::CatalogIndexPage(QWidget *parent)
{ {
m_indexModel = new IndexModel(this); m_indexModel = new IndexModel(this);
m_sortFilterProxy->setSourceModel(m_indexModel); m_sortFilterProxy->setSourceModel(m_indexModel);
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this)); m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged, connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,

View file

@ -33,17 +33,13 @@ CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
void CatalogSequencesPage::retranslateUi() void CatalogSequencesPage::retranslateUi()
{ {
// auto set_tabtext = [this] (QWidget *widget, QString translation) {
// m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation);
// };
// set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr));
} }
void CatalogSequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat) void CatalogSequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
{ {
m_catalog = cat; m_catalog = cat;
m_model->setCatalog(cat); m_model->setCatalog(cat);
m_sequenceTable->resizeColumnsToContents();
} }
void CatalogSequencesPage::sequenceTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous) void CatalogSequencesPage::sequenceTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)

View file

@ -15,12 +15,15 @@
#include <QApplication> #include <QApplication>
#include <QStringBuilder> #include <QStringBuilder>
#include <QSortFilterProxyModel>
#include <QTableWidget> #include <QTableWidget>
CatalogTablesPage::CatalogTablesPage(QWidget *parent) CatalogTablesPage::CatalogTablesPage(QWidget *parent)
: QSplitter(Qt::Horizontal, parent) : QSplitter(Qt::Horizontal, parent)
{ {
m_tableView = new PgLabTableView(this); m_tableView = new PgLabTableView(this);
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
m_detailsTabs = new QTabWidget(this); m_detailsTabs = new QTabWidget(this);
// Populate splitter // Populate splitter
@ -29,7 +32,10 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
// Setup model(s) // Setup model(s)
m_tablesModel = new TablesTableModel(this); m_tablesModel = new TablesTableModel(this);
m_tableView->setModel(m_tablesModel); m_tablesSortFilter = new QSortFilterProxyModel(this);
m_tablesSortFilter->setSourceModel(m_tablesModel);
m_tableView->setModel(m_tablesSortFilter);
m_tableView->setSortingEnabled(true);
// - Columns page // - Columns page
m_columnsPage = new ColumnPage(this); m_columnsPage = new ColumnPage(this);
@ -70,7 +76,7 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
this, &CatalogTablesPage::tableListTable_layoutChanged); this, &CatalogTablesPage::tableListTable_layoutChanged);
} }
void CatalogTablesPage::retranslateUi(bool all) void CatalogTablesPage::retranslateUi(bool /*all*/)
{ {
auto set_tabtext = [this] (QWidget *widget, QString translation) { auto set_tabtext = [this] (QWidget *widget, QString translation) {
m_detailsTabs->setTabText(m_detailsTabs->indexOf(widget), translation); m_detailsTabs->setTabText(m_detailsTabs->indexOf(widget), translation);

View file

@ -16,6 +16,7 @@ class PgLabTableView;
class PropertiesPage; class PropertiesPage;
class QTabWidget; class QTabWidget;
class SqlCodePreview; class SqlCodePreview;
class QSortFilterProxyModel;
class TablesTableModel; class TablesTableModel;
class TriggerPage; class TriggerPage;
@ -32,6 +33,7 @@ public:
private: private:
PgLabTableView *m_tableView = nullptr; PgLabTableView *m_tableView = nullptr;
TablesTableModel* m_tablesModel = nullptr; TablesTableModel* m_tablesModel = nullptr;
QSortFilterProxyModel *m_tablesSortFilter = nullptr;
// Details // Details
QTabWidget *m_detailsTabs = nullptr; QTabWidget *m_detailsTabs = nullptr;