Code refactoring - HistoryWidget, add clearHistoryLayout and loadHistory methods
This commit is contained in:
@@ -298,6 +298,7 @@ void Controller::updateConfigComponents()
|
||||
void Controller::showRecentScreenshots()
|
||||
{
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->loadHistory();
|
||||
pHistory->exec();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user