Improvement to the ServerWindow
- sorting of Roles - resizeColumns voor zowel databases als roles - boolean columns now display check mark and cross
This commit is contained in:
parent
a3ba4d7c98
commit
9c9e78c54b
8 changed files with 71 additions and 44 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include "BaseTableModel.h"
|
#include "BaseTableModel.h"
|
||||||
|
#include "CustomDataRole.h"
|
||||||
#include "ResultTableModelUtil.h"
|
#include "ResultTableModelUtil.h"
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include "Pgsql_oids.h"
|
#include "Pgsql_oids.h"
|
||||||
|
|
@ -11,23 +12,17 @@ QVariant BaseTableModel::data(const QModelIndex &index, int role) const
|
||||||
Oid oid = getType(index.column());
|
Oid oid = getType(index.column());
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
v = getData(index);
|
v = getData(index);
|
||||||
if (oid == bool_oid) {
|
|
||||||
v = FormatBoolForDisplay(v.toBool());
|
|
||||||
}
|
}
|
||||||
|
else if (role == CustomDataTypeRole) {
|
||||||
|
v = oid;
|
||||||
}
|
}
|
||||||
else if (role == Qt::TextAlignmentRole) {
|
else if (role == CustomDataMeaningRole) {
|
||||||
v = (int)GetDefaultAlignmentForType(oid);
|
v = getDataMeaning(index);
|
||||||
}
|
|
||||||
else if (role == Qt::ForegroundRole) {
|
|
||||||
if (oid == bool_oid) {
|
|
||||||
QVariant d = getData(index);
|
|
||||||
if (d.type() == QVariant::Bool) {
|
|
||||||
v = QBrush(GetDefaultBoolColor(d.toBool()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
v = QBrush(GetDefaultColorForType(oid));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant BaseTableModel::getDataMeaning(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return static_cast<int>(DataMeaningNormal);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual Oid getType(int column) const = 0;
|
virtual Oid getType(int column) const = 0;
|
||||||
virtual QVariant getData(const QModelIndex &index) const = 0;
|
virtual QVariant getData(const QModelIndex &index) const = 0;
|
||||||
|
virtual QVariant getDataMeaning(const QModelIndex &index) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
#include "DatabasesTableModel.h"
|
#include "DatabasesTableModel.h"
|
||||||
|
#include "CustomDataRole.h"
|
||||||
|
#include "ScopeGuard.h"
|
||||||
#include "catalog/PgDatabaseCatalog.h"
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
#include "catalog/PgDatabaseContainer.h"
|
#include "catalog/PgDatabaseContainer.h"
|
||||||
#include "catalog/PgAuthIdContainer.h"
|
#include "catalog/PgAuthIdContainer.h"
|
||||||
|
|
@ -14,9 +16,10 @@ DatabasesTableModel::DatabasesTableModel(QObject *parent)
|
||||||
void DatabasesTableModel::setDatabaseList(std::shared_ptr<const PgDatabaseCatalog> cat)
|
void DatabasesTableModel::setDatabaseList(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
SCOPE_EXIT { endResetModel(); };
|
||||||
|
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
m_databases = cat->databases();
|
m_databases = cat->databases();
|
||||||
endResetModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DatabasesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DatabasesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
|
@ -90,13 +93,13 @@ Oid DatabasesTableModel::getType(int column) const
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case AllowConnCol:
|
case AllowConnCol:
|
||||||
case IsTemplateCol:
|
case IsTemplateCol:
|
||||||
oid = bool_oid;
|
oid = Pgsql::bool_oid;
|
||||||
break;
|
break;
|
||||||
case ConnLimitCol:
|
case ConnLimitCol:
|
||||||
oid = int4_oid;
|
oid = Pgsql::int4_oid;
|
||||||
break;
|
break;
|
||||||
case SizeCol:
|
case SizeCol:
|
||||||
oid = int8_oid;
|
oid = Pgsql::int8_oid;
|
||||||
break;
|
break;
|
||||||
case AclCol:
|
case AclCol:
|
||||||
case CollateCol:
|
case CollateCol:
|
||||||
|
|
@ -106,7 +109,7 @@ Oid DatabasesTableModel::getType(int column) const
|
||||||
case NameCol:
|
case NameCol:
|
||||||
case TablespaceCol:
|
case TablespaceCol:
|
||||||
case CommentCol:
|
case CommentCol:
|
||||||
oid = varchar_oid;
|
oid = Pgsql::varchar_oid;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
oid = InvalidOid;
|
oid = InvalidOid;
|
||||||
|
|
@ -163,3 +166,11 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant DatabasesTableModel::getDataMeaning(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (index.column() == SizeCol)
|
||||||
|
return static_cast<int>(DataMeaningBytes);
|
||||||
|
|
||||||
|
return BaseTableModel::getDataMeaning(index);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ public:
|
||||||
virtual Oid getType(int column) const override;
|
virtual Oid getType(int column) const override;
|
||||||
virtual QVariant getData(const QModelIndex &index) const override;
|
virtual QVariant getData(const QModelIndex &index) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QVariant getDataMeaning(const QModelIndex &index) const override;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||||
std::shared_ptr<const PgDatabaseContainer> m_databases;
|
std::shared_ptr<const PgDatabaseContainer> m_databases;
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,13 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
||||||
: GetDefaultColorForType(oid);
|
: GetDefaultColorForType(oid);
|
||||||
|
|
||||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||||
if (oid == Pgsql::bool_oid)
|
if (oid == Pgsql::bool_oid) {
|
||||||
option->text = FormatBoolForDisplay(value.toBool());
|
bool b = value.toBool();
|
||||||
|
forground_color = GetDefaultBoolColor(b);
|
||||||
|
option->text = FormatBoolForDisplay(b);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
forground_color = GetDefaultColorForType(oid);
|
||||||
if (meaning == DataMeaningBytes) {
|
if (meaning == DataMeaningBytes) {
|
||||||
QString suffix;
|
QString suffix;
|
||||||
auto s = value.toLongLong();
|
auto s = value.toLongLong();
|
||||||
|
|
@ -140,8 +144,8 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
||||||
// option->text = ((f > 0) ? s.left(f) : s).toString();
|
// option->text = ((f > 0) ? s.left(f) : s).toString();
|
||||||
option->text = s;
|
option->text = s;
|
||||||
}
|
}
|
||||||
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
|
||||||
}
|
}
|
||||||
|
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));
|
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,10 @@ QColor GetDefaultColorForType(Oid o)
|
||||||
|
|
||||||
QString FormatBoolForDisplay(bool v)
|
QString FormatBoolForDisplay(bool v)
|
||||||
{
|
{
|
||||||
return v ? "TRUE" : "FALSE";
|
static QString t(QChar(0x2713));
|
||||||
|
static QString f(QChar(0x2717));
|
||||||
|
|
||||||
|
return v ? t : f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,16 @@ ServerWindow::ServerWindow(MasterController *master, QWidget *parent)
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_databasesModel = new DatabasesTableModel(this);
|
m_databasesModel = new DatabasesTableModel(this);
|
||||||
|
|
||||||
auto databasesSortFilter = new QSortFilterProxyModel(this);
|
auto databasesSortFilter = new QSortFilterProxyModel(this);
|
||||||
databasesSortFilter->setSourceModel(m_databasesModel);
|
databasesSortFilter->setSourceModel(m_databasesModel);
|
||||||
|
|
||||||
ui->databasesTableView->setModel(databasesSortFilter);
|
ui->databasesTableView->setModel(databasesSortFilter);
|
||||||
ui->databasesTableView->setSortingEnabled(true);
|
ui->databasesTableView->setSortingEnabled(true);
|
||||||
|
|
||||||
m_rolesModel = new RolesTableModel(this);
|
m_rolesModel = new RolesTableModel(this);
|
||||||
ui->rolesTableView->setModel(m_rolesModel);
|
auto rolesSortFilter = new QSortFilterProxyModel(this);
|
||||||
|
rolesSortFilter->setSourceModel(m_rolesModel);
|
||||||
|
ui->rolesTableView->setModel(rolesSortFilter);
|
||||||
|
ui->rolesTableView->setSortingEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerWindow::~ServerWindow()
|
ServerWindow::~ServerWindow()
|
||||||
|
|
@ -39,7 +40,10 @@ void ServerWindow::setConfig(const ConnectionConfig &config)
|
||||||
auto cat = m_database->catalog();
|
auto cat = m_database->catalog();
|
||||||
if (cat) {
|
if (cat) {
|
||||||
m_databasesModel->setDatabaseList(cat);
|
m_databasesModel->setDatabaseList(cat);
|
||||||
|
ui->databasesTableView->resizeColumnsToContents();
|
||||||
|
|
||||||
m_rolesModel->setRoleList(cat->authIds());
|
m_rolesModel->setRoleList(cat->authIds());
|
||||||
|
ui->rolesTableView->resizeColumnsToContents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const OpenDatabaseException &ex) {
|
catch (const OpenDatabaseException &ex) {
|
||||||
|
|
|
||||||
|
|
@ -50,16 +50,16 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="databasesTableView">
|
<widget class="PgLabTableView" name="databasesTableView">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="verticalHeaderDefaultSectionSize">
|
|
||||||
<number>20</number>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderMinimumSectionSize">
|
<attribute name="verticalHeaderMinimumSectionSize">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderDefaultSectionSize">
|
||||||
|
<number>20</number>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
@ -86,12 +86,12 @@
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="verticalHeaderDefaultSectionSize">
|
|
||||||
<number>20</number>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderMinimumSectionSize">
|
<attribute name="verticalHeaderMinimumSectionSize">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderDefaultSectionSize">
|
||||||
|
<number>20</number>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
@ -114,16 +114,16 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="rolesTableView">
|
<widget class="PgLabTableView" name="rolesTableView">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="verticalHeaderDefaultSectionSize">
|
|
||||||
<number>20</number>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderMinimumSectionSize">
|
<attribute name="verticalHeaderMinimumSectionSize">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="verticalHeaderDefaultSectionSize">
|
||||||
|
<number>20</number>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
@ -138,12 +138,19 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>23</height>
|
<height>30</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PgLabTableView</class>
|
||||||
|
<extends>QTableView</extends>
|
||||||
|
<header>PgLabTableView.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue