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

@ -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()));