Manager: Optimize details loading code
This commit is contained in:
@@ -157,58 +157,36 @@ VMManagerDetailSection::setSections()
|
|||||||
{
|
{
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
|
for (const auto& section : sections) {
|
||||||
|
QStringList sectionsToAdd = section.value.split(sectionSeparator);
|
||||||
|
QLabel *labelKey = nullptr;
|
||||||
|
|
||||||
for ( const auto& section : sections) {
|
for (const auto& line : sectionsToAdd) {
|
||||||
// if the string contains the separator (defined elsewhere) then split and
|
if (line.isEmpty()) {
|
||||||
// add each entry on a new line. Otherwise, just add the one.
|
|
||||||
QStringList sectionsToAdd;
|
|
||||||
if(section.value.contains(sectionSeparator)) {
|
|
||||||
sectionsToAdd = section.value.split(sectionSeparator);
|
|
||||||
} else {
|
|
||||||
sectionsToAdd.push_back(section.value);
|
|
||||||
}
|
|
||||||
bool keyAdded = false;
|
|
||||||
|
|
||||||
// Reduce the text size for the label
|
|
||||||
// First, get the existing font
|
|
||||||
auto reference_label = new QLabel();
|
|
||||||
auto smaller_font = reference_label->font();
|
|
||||||
// Get a smaller size
|
|
||||||
// Not sure if I like the smaller size, back to regular for now
|
|
||||||
// auto smaller_size = 0.85 * smaller_font.pointSize();
|
|
||||||
const auto smaller_size = 1 * smaller_font.pointSize();
|
|
||||||
// Set the font to the smaller size
|
|
||||||
smaller_font.setPointSizeF(smaller_size);
|
|
||||||
delete reference_label;
|
|
||||||
|
|
||||||
for(const auto&line : sectionsToAdd) {
|
|
||||||
if(line.isEmpty()) {
|
|
||||||
// Don't bother adding entries if the values are blank
|
// Don't bother adding entries if the values are blank
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto labelKey = new QLabel();
|
|
||||||
labelKey->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
|
||||||
const auto labelValue = new QLabel();
|
const auto labelValue = new QLabel();
|
||||||
labelKey->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
labelValue->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||||
labelValue->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse);
|
labelValue->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse);
|
||||||
labelKey->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse);
|
|
||||||
|
|
||||||
// Assign that new, smaller font to the label
|
|
||||||
labelKey->setFont(smaller_font);
|
|
||||||
labelValue->setFont(smaller_font);
|
|
||||||
|
|
||||||
labelKey->setText(QCoreApplication::translate("", QString(section.name + ":").toUtf8().data()));
|
|
||||||
labelValue->setText(line);
|
labelValue->setText(line);
|
||||||
if(!keyAdded) {
|
|
||||||
frameGridLayout->addWidget(labelKey, row, 0, Qt::AlignLeft);
|
|
||||||
keyAdded = true;
|
|
||||||
}
|
|
||||||
frameGridLayout->addWidget(labelValue, row, 1, Qt::AlignLeft);
|
frameGridLayout->addWidget(labelValue, row, 1, Qt::AlignLeft);
|
||||||
|
|
||||||
|
if (!labelKey) {
|
||||||
|
labelKey = new QLabel();
|
||||||
|
labelKey->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||||
|
labelKey->setTextInteractionFlags(labelValue->textInteractionFlags());
|
||||||
|
labelKey->setText(QCoreApplication::translate("", QString(section.name + ":").toUtf8().data()));
|
||||||
|
frameGridLayout->addWidget(labelKey, row, 0, Qt::AlignLeft);
|
||||||
|
}
|
||||||
|
|
||||||
const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
frameGridLayout->addItem(hSpacer, row, 2);
|
frameGridLayout->addItem(hSpacer, row, 2);
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collapseButton->setContent(ui->detailFrame);
|
collapseButton->setContent(ui->detailFrame);
|
||||||
if (sections.size())
|
if (sections.size())
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@@ -231,8 +209,6 @@ VMManagerDetailSection::clear()
|
|||||||
|
|
||||||
delete frameGridLayout;
|
delete frameGridLayout;
|
||||||
frameGridLayout = new QGridLayout();
|
frameGridLayout = new QGridLayout();
|
||||||
qint32 *left = nullptr, *top = nullptr, *right = nullptr, *bottom = nullptr;
|
|
||||||
frameGridLayout->getContentsMargins(left, top, right, bottom);
|
|
||||||
frameGridLayout->setContentsMargins(getMargins(MarginSection::DisplayGrid));
|
frameGridLayout->setContentsMargins(getMargins(MarginSection::DisplayGrid));
|
||||||
ui->detailFrame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
ui->detailFrame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||||
ui->detailFrame->setLayout(frameGridLayout);
|
ui->detailFrame->setLayout(frameGridLayout);
|
||||||
@@ -283,7 +259,7 @@ void CollapseButton::setButtonText(const QString &text) {
|
|||||||
void CollapseButton::setContent(QWidget *content) {
|
void CollapseButton::setContent(QWidget *content) {
|
||||||
assert(content != nullptr);
|
assert(content != nullptr);
|
||||||
content_ = content;
|
content_ = content;
|
||||||
/*const auto animation_ = new QPropertyAnimation(content_, "maximumHeight"); // QObject with auto delete
|
const auto animation_ = new QPropertyAnimation(content_, "maximumHeight"); // QObject with auto delete
|
||||||
animation_->setStartValue(0);
|
animation_->setStartValue(0);
|
||||||
animation_->setEasingCurve(QEasingCurve::InOutQuad);
|
animation_->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animation_->setDuration(300);
|
animation_->setDuration(300);
|
||||||
@@ -293,16 +269,16 @@ void CollapseButton::setContent(QWidget *content) {
|
|||||||
animator_.addAnimation(animation_);
|
animator_.addAnimation(animation_);
|
||||||
if (!isChecked()) {
|
if (!isChecked()) {
|
||||||
content->setMaximumHeight(0);
|
content->setMaximumHeight(0);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollapseButton::hideContent() {
|
void CollapseButton::hideContent() {
|
||||||
/*animator_.setDirection(QAbstractAnimation::Backward);
|
animator_.setDirection(QAbstractAnimation::Backward);
|
||||||
animator_.start();*/
|
animator_.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollapseButton::showContent() {
|
void CollapseButton::showContent() {
|
||||||
/*animator_.setDirection(QAbstractAnimation::Forward);
|
animator_.setDirection(QAbstractAnimation::Forward);
|
||||||
animator_.start();*/
|
animator_.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user