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 "CustomDataRole.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include <QBrush>
|
||||
#include "Pgsql_oids.h"
|
||||
|
|
@ -11,23 +12,17 @@ QVariant BaseTableModel::data(const QModelIndex &index, int role) const
|
|||
Oid oid = getType(index.column());
|
||||
if (role == Qt::DisplayRole) {
|
||||
v = getData(index);
|
||||
if (oid == bool_oid) {
|
||||
v = FormatBoolForDisplay(v.toBool());
|
||||
}
|
||||
else if (role == CustomDataTypeRole) {
|
||||
v = oid;
|
||||
}
|
||||
else if (role == Qt::TextAlignmentRole) {
|
||||
v = (int)GetDefaultAlignmentForType(oid);
|
||||
}
|
||||
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));
|
||||
}
|
||||
else if (role == CustomDataMeaningRole) {
|
||||
v = getDataMeaning(index);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
QVariant BaseTableModel::getDataMeaning(const QModelIndex &index) const
|
||||
{
|
||||
return static_cast<int>(DataMeaningNormal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public:
|
|||
protected:
|
||||
virtual Oid getType(int column) 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 "CustomDataRole.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "catalog/PgDatabaseContainer.h"
|
||||
#include "catalog/PgAuthIdContainer.h"
|
||||
|
|
@ -14,9 +16,10 @@ DatabasesTableModel::DatabasesTableModel(QObject *parent)
|
|||
void DatabasesTableModel::setDatabaseList(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
beginResetModel();
|
||||
SCOPE_EXIT { endResetModel(); };
|
||||
|
||||
m_catalog = cat;
|
||||
m_databases = cat->databases();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant DatabasesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
|
@ -90,13 +93,13 @@ Oid DatabasesTableModel::getType(int column) const
|
|||
switch (column) {
|
||||
case AllowConnCol:
|
||||
case IsTemplateCol:
|
||||
oid = bool_oid;
|
||||
oid = Pgsql::bool_oid;
|
||||
break;
|
||||
case ConnLimitCol:
|
||||
oid = int4_oid;
|
||||
oid = Pgsql::int4_oid;
|
||||
break;
|
||||
case SizeCol:
|
||||
oid = int8_oid;
|
||||
oid = Pgsql::int8_oid;
|
||||
break;
|
||||
case AclCol:
|
||||
case CollateCol:
|
||||
|
|
@ -106,7 +109,7 @@ Oid DatabasesTableModel::getType(int column) const
|
|||
case NameCol:
|
||||
case TablespaceCol:
|
||||
case CommentCol:
|
||||
oid = varchar_oid;
|
||||
oid = Pgsql::varchar_oid;
|
||||
break;
|
||||
default:
|
||||
oid = InvalidOid;
|
||||
|
|
@ -163,3 +166,11 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
|
|||
}
|
||||
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 QVariant getData(const QModelIndex &index) const override;
|
||||
|
||||
protected:
|
||||
virtual QVariant getDataMeaning(const QModelIndex &index) const override;
|
||||
private:
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::shared_ptr<const PgDatabaseContainer> m_databases;
|
||||
|
|
|
|||
|
|
@ -103,9 +103,13 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
: GetDefaultColorForType(oid);
|
||||
|
||||
option->features |= QStyleOptionViewItem::HasDisplay;
|
||||
if (oid == Pgsql::bool_oid)
|
||||
option->text = FormatBoolForDisplay(value.toBool());
|
||||
if (oid == Pgsql::bool_oid) {
|
||||
bool b = value.toBool();
|
||||
forground_color = GetDefaultBoolColor(b);
|
||||
option->text = FormatBoolForDisplay(b);
|
||||
}
|
||||
else {
|
||||
forground_color = GetDefaultColorForType(oid);
|
||||
if (meaning == DataMeaningBytes) {
|
||||
QString suffix;
|
||||
auto s = value.toLongLong();
|
||||
|
|
@ -140,8 +144,8 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
|
|||
// option->text = ((f > 0) ? s.left(f) : s).toString();
|
||||
option->text = s;
|
||||
}
|
||||
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
||||
}
|
||||
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
|
||||
}
|
||||
else {
|
||||
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));
|
||||
|
|
|
|||
|
|
@ -54,7 +54,10 @@ QColor GetDefaultColorForType(Oid o)
|
|||
|
||||
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);
|
||||
|
||||
m_databasesModel = new DatabasesTableModel(this);
|
||||
|
||||
auto databasesSortFilter = new QSortFilterProxyModel(this);
|
||||
databasesSortFilter->setSourceModel(m_databasesModel);
|
||||
|
||||
ui->databasesTableView->setModel(databasesSortFilter);
|
||||
ui->databasesTableView->setSortingEnabled(true);
|
||||
|
||||
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()
|
||||
|
|
@ -39,7 +40,10 @@ void ServerWindow::setConfig(const ConnectionConfig &config)
|
|||
auto cat = m_database->catalog();
|
||||
if (cat) {
|
||||
m_databasesModel->setDatabaseList(cat);
|
||||
ui->databasesTableView->resizeColumnsToContents();
|
||||
|
||||
m_rolesModel->setRoleList(cat->authIds());
|
||||
ui->rolesTableView->resizeColumnsToContents();
|
||||
}
|
||||
}
|
||||
catch (const OpenDatabaseException &ex) {
|
||||
|
|
|
|||
|
|
@ -50,16 +50,16 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableView" name="databasesTableView">
|
||||
<widget class="PgLabTableView" name="databasesTableView">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>16</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -86,12 +86,12 @@
|
|||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>16</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -114,16 +114,16 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableView" name="rolesTableView">
|
||||
<widget class="PgLabTableView" name="rolesTableView">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>16</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
@ -138,12 +138,19 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>23</height>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>PgLabTableView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>PgLabTableView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue