Code refactoring - HistoryWidget, add clearHistoryLayout and loadHistory methods

This commit is contained in:
Yuriy Puchkov
2020-10-16 10:08:13 +03:00
parent b5f552badc
commit 8e25f438f2
4 changed files with 23 additions and 4 deletions

View File

@@ -41,8 +41,6 @@ HistoryWidget::HistoryWidget(QWidget* parent)
QWidget* widget = new QWidget();
scrollArea->setWidget(widget);
widget->setLayout(m_pVBox);
loadHistory();
}
HistoryWidget::~HistoryWidget()
@@ -50,8 +48,26 @@ HistoryWidget::~HistoryWidget()
delete m_notification;
}
void HistoryWidget::clearHistoryLayout(QLayout* layout)
{
QLayoutItem* child;
while (layout->count() != 0) {
child = layout->takeAt(0);
if (child->layout() != 0) {
clearHistoryLayout(child->layout());
} else if (child->widget() != 0) {
delete child->widget();
}
delete child;
}
}
void HistoryWidget::loadHistory()
{
// clear old history if exists
clearHistoryLayout(m_pVBox);
// read history files
History history = History();
QList<QString> historyFiles = history.history();