Show sizes

table, index, toast and total size per Table
size of each index
This commit is contained in:
eelke 2021-03-10 19:06:40 +01:00
parent d6aeef492d
commit 11459e1e12
17 changed files with 138 additions and 28 deletions

View file

@ -131,7 +131,7 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
int ColumnTableModel::rowCount(const QModelIndex &/*parent*/) const
{
return m_columns.size();
return static_cast<int>(m_columns.size());
}
int ColumnTableModel::columnCount(const QModelIndex &/*parent*/) const

View file

@ -67,7 +67,7 @@ QVariant ConstraintModel::headerData(int section, Qt::Orientation orientation, i
int ConstraintModel::rowCount(const QModelIndex &) const
{
return m_constraints.size();
return static_cast<int>(m_constraints.size());
}
int ConstraintModel::columnCount(const QModelIndex &) const

View file

@ -13,10 +13,17 @@ enum class ReferencedType {
PgRole
};
///
enum DataMeaning {
DataMeaningNormal,
DataMeaningBytes ///< the value represents bytes pretty print in KiB, MiB, GiB, TiB, PiB, EiB
};
enum CustomDataRole {
CustomDataTypeRole = Qt::UserRole, ///< Requist the basic type of the value
CustomReferencedTypeRole, ///<
// Add other enum before this one is we might want to have multiple hidden values
CustomDataMeaningRole,
// Add other enum before this one as we might want to have multiple hidden values
FirstHiddenValue, ///< Used to request value from a model which is not handed to the view
};

View file

@ -63,6 +63,9 @@ QVariant IndexModel::headerData(int section, Qt::Orientation orientation, int ro
case ConditionCol:
c = tr("Condition");
break;
case SizeCol:
c = tr("Size");
break;
// case DefinitionCol:
// c = tr("Definition");
// break;
@ -99,6 +102,10 @@ QVariant IndexModel::getData(const QModelIndex &index) const
case ConditionCol:
break;
case SizeCol:
v = dat.sizeBytes;
break;
}
return v;
}
@ -110,5 +117,13 @@ QVariant IndexModel::data(const QModelIndex &index, int role) const
v = getData(index);
else if (role == CustomDataTypeRole)
v = getType(index.column());
return v;
else if (role == CustomDataMeaningRole) {
switch (index.column()) {
case SizeCol:
return static_cast<int>(DataMeaningBytes);
default:
return static_cast<int>(DataMeaningNormal);
}
}
return v;
}

View file

@ -22,6 +22,7 @@ public:
AmCol, ///< Access Method
ColumnsCol, ///
ConditionCol,
SizeCol,
colCount };
// oid

View file

@ -87,6 +87,11 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
if (value.isValid())
oid = value.toUInt(); //getType(index.column());
value = index.data(CustomDataMeaningRole);
DataMeaning meaning = value.isValid()
? static_cast<DataMeaning>(value.toInt())
: DataMeaningNormal;
value = index.data(Qt::DisplayRole);
option->displayAlignment = GetDefaultAlignmentForType(oid);
@ -96,18 +101,47 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option,
QColor forground_color = oid == Pgsql::bool_oid
? GetDefaultBoolColor(value.toBool())
: GetDefaultColorForType(oid);
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
option->features |= QStyleOptionViewItem::HasDisplay;
if (oid == Pgsql::bool_oid)
option->text = FormatBoolForDisplay(value.toBool());
else {
auto str = value.toString();
auto s = str.left(100);
// auto f = s.indexOf('\n');
// option->text = ((f > 0) ? s.left(f) : s).toString();
option->text = s;
}
if (meaning == DataMeaningBytes) {
QString suffix;
auto s = value.toLongLong();
double val;
if (s > 1024 * 1024 * 1000) {
val = s / (1024 * 1024 * 1024);
suffix = "GiB";
forground_color = QColorConstants::Svg::darkorange;
option->font.setBold(true);
}
else if (s > 1024 * 1000) {
val = s / (1024 * 1024);
suffix = "MiB";
forground_color = QColorConstants::Svg::darkgoldenrod;
}
else if (s > 1000) {
val = s / 1024;
suffix = "KiB";
forground_color = QColorConstants::Svg::darkgreen;
}
else {
val = s;
suffix = "B";
forground_color = QColorConstants::Svg::darkblue;
}
option->text = QString{ "%1 %2" }.arg(val, 3, 'g', -1 ).arg(suffix) ;
}
else {
auto str = value.toString();
auto s = str.left(100);
// auto f = s.indexOf('\n');
// option->text = ((f > 0) ? s.left(f) : s).toString();
option->text = s;
}
option->palette.setBrush(QPalette::Text, QBrush(forground_color));
}
}
else {
option->palette.setBrush(QPalette::Text, QBrush(GetDefaultNullColor()));

View file

@ -100,7 +100,8 @@ QVariant PropertyProxyModel::data(const QModelIndex &proxyIndex, int role) const
void PropertyProxyModel::setActiveRow(const QModelIndex &row)
{
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

View file

@ -20,7 +20,7 @@ public:
public Q_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
* The column part of the index is not used QModelIndex is used to make it easy to connect to
* QItemSelectionModel::currentRowChanged
*/
void setActiveRow(const QModelIndex &row);

View file

@ -132,7 +132,11 @@ QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation,
case OptionsCol: return tr("Options");
case AclCol: return tr("ACL");
case CommentCol: return tr("Comment");
}
case TotalSize: return tr("Total size");
case TableSize: return tr("Table size");
case IndexSize: return tr("Index size");
case ToastSize: return tr("TOAST size");
}
}
}
return QVariant();
@ -153,6 +157,12 @@ Oid TablesTableModel::getType(int column) const
{
Oid oid;
switch (column) {
case TotalSize:
case TableSize:
case IndexSize:
case ToastSize:
oid = Pgsql::int8_oid;
break;
case TablespaceCol:
case OwnerCol:
case NameCol:
@ -179,7 +189,11 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
case OptionsCol: break;
case AclCol: return t.aclString();
case CommentCol: return t.description;
}
case TotalSize: return t.totalBytes;
case TableSize: return t.totalBytes - t.indexBytes - t.toastBytes;
case IndexSize: return t.indexBytes;
case ToastSize: return t.toastBytes;
}
return QVariant();
}
@ -207,5 +221,17 @@ QVariant TablesTableModel::data(const QModelIndex &index, int role) const
return getData(index);
else if (role == CustomDataTypeRole)
return getType(index.column());
else if (role == CustomDataMeaningRole) {
switch (index.column()) {
case TotalSize:
case TableSize:
case IndexSize:
case ToastSize:
return static_cast<int>(DataMeaningBytes);
default:
return static_cast<int>(DataMeaningNormal);
}
}
return QVariant();
}

View file

@ -23,6 +23,11 @@ public:
OptionsCol,
AclCol,
CommentCol,
TotalSize,
TableSize,
IndexSize,
ToastSize,
colCount };
TablesTableModel(QObject *parent);

View file

@ -58,9 +58,6 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
m_propertiesPage->setSourceModel(m_tablesModel);
m_detailsTabs->addTab(m_propertiesPage, "");
connect(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged,
m_propertiesPage, &PropertiesPage::setActiveRow);
// - Trigger page
m_triggerPage = new TriggerPage(this);
m_detailsTabs->addTab(m_triggerPage, "");
@ -129,13 +126,17 @@ void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex &curr
{
if (current.row() != previous.row()) {
if (current.isValid()) {
auto row = m_tablesSortFilter->mapToSource(current).row();
auto sourceIndex = m_tablesSortFilter->mapToSource(current);
auto row = sourceIndex.row();
PgClass table = m_tablesModel->getTable(row);
selectedTableChanged(table);
m_propertiesPage->setActiveRow(sourceIndex);
}
else
else {
selectedTableChanged({});
}
m_propertiesPage->setActiveRow({});
}
}
}