Clear layout before adding more widgets

This commit is contained in:
ballessay 2017-04-26 01:30:36 +02:00 committed by C. Balles
parent ab28142ec5
commit 06e82c8421

View File

@ -9,6 +9,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include <QLayoutItem>
Dashboard::Dashboard(MainWindow *main, QWidget *parent) :
@ -40,7 +41,6 @@ void Dashboard::refresh()
void Dashboard::updateContents()
{
// Parse and add JSON file info
QString info = this->main->core->getFileInfo();
@ -150,11 +150,28 @@ void Dashboard::updateContents()
QString libs = this->main->core->cmd("il");
QStringList lines = libs.split("\n", QString::SkipEmptyParts);
if (! lines.isEmpty())
if (!lines.isEmpty())
{
lines.removeFirst();
lines.removeLast();
}
// dunno: why not label->setText(lines.join("\n")?
while (ui->verticalLayout_2->count() > 0)
{
QLayoutItem *item = ui->verticalLayout_2->takeAt(0);
if (item != nullptr)
{
QWidget *w = item->widget();
if (w != nullptr)
{
w->deleteLater();
}
delete item;
}
}
foreach (QString lib, lines)
{
QLabel *label = new QLabel(this);
@ -162,6 +179,10 @@ void Dashboard::updateContents()
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
ui->verticalLayout_2->addWidget(label);
}
QSpacerItem *spacer = new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding);
ui->verticalLayout_2->addSpacerItem(spacer);
@ -198,4 +219,3 @@ void Dashboard::updateContents()
code2.replace("WOEM", data);
ui->polarWebView->setHtml(code2);
}