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

@@ -298,6 +298,7 @@ void Controller::updateConfigComponents()
void Controller::showRecentScreenshots()
{
HistoryWidget* pHistory = new HistoryWidget();
pHistory->loadHistory();
pHistory->exec();
}

View File

@@ -58,6 +58,7 @@ bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
if (m_history == nullptr) {
m_history = new HistoryWidget();
m_history->loadHistory();
}
m_history->show();
}

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

View File

@@ -21,10 +21,11 @@ public:
explicit HistoryWidget(QWidget* parent = nullptr);
~HistoryWidget();
signals:
void loadHistory();
private:
void loadHistory();
void clearHistoryLayout(QLayout* layout);
void addLine(const QString&, const QString&);
void setEmptyMessage();
void removeItem(QLayout* pl,