From f4af5e6cc108c026b3e599458474cfe1cc1a1338 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 3 May 2017 02:23:55 +0200 Subject: [PATCH] Ref T28, settings for updater --- .../components/settingsmodelcomponent.cpp | 40 +++++++++++++ .../components/settingsmodelcomponent.h | 11 ++++ .../components/settingsmodelcomponent.ui | 57 ++++++++++++++++--- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/src/blackgui/components/settingsmodelcomponent.cpp b/src/blackgui/components/settingsmodelcomponent.cpp index ed9a6164f..1cacdd5a3 100644 --- a/src/blackgui/components/settingsmodelcomponent.cpp +++ b/src/blackgui/components/settingsmodelcomponent.cpp @@ -10,6 +10,12 @@ #include "settingsmodelcomponent.h" #include "ui_settingsmodelcomponent.h" +#include "blackmisc/logmessage.h" +#include + +using namespace BlackMisc; +using namespace BlackGui::Settings; + namespace BlackGui { namespace Components @@ -19,9 +25,43 @@ namespace BlackGui ui(new Ui::CSettingsModelComponent) { ui->setupUi(this); + ui->le_ConsolidateSecs->setValidator(new QIntValidator(0, TBackgroundConsolidation::maxSecs(), ui->le_ConsolidateSecs)); + + this->cacheChanged(); + connect(ui->le_ConsolidateSecs, &QLineEdit::returnPressed, this, &CSettingsModelComponent::consolidationEntered); + static QString lbl("Consolidate (%1-%2s):"); + ui->lbl_Consolidate->setText(lbl.arg(TBackgroundConsolidation::minSecs()).arg(TBackgroundConsolidation::maxSecs())); } CSettingsModelComponent::~CSettingsModelComponent() { } + + int CSettingsModelComponent::getBackgroundUpdaterIntervallSecs() const + { + const QString v = ui->le_ConsolidateSecs->text().trimmed(); + if (v.isEmpty()) { return -1; } + bool ok = false; + const int secs = v.toInt(&ok); + return ok ? secs : -1; + } + + void CSettingsModelComponent::consolidationEntered() + { + int v = this->getBackgroundUpdaterIntervallSecs(); + if (v < TBackgroundConsolidation::minSecs()) v = -1; + + const CStatusMessage m = m_consolidationSetting.setAndSave(v); + CLogMessage::preformatted(m); + this->cacheChanged(); + } + + void CSettingsModelComponent::cacheChanged() + { + const int v = m_consolidationSetting.get(); + const bool on = v > 0; + const QString s = on ? QString::number(v) : ""; + ui->le_ConsolidateSecs->setText(s); + ui->comp_Led->setOn(on); + } } // ns } // ns diff --git a/src/blackgui/components/settingsmodelcomponent.h b/src/blackgui/components/settingsmodelcomponent.h index cd1c76621..c0f209311 100644 --- a/src/blackgui/components/settingsmodelcomponent.h +++ b/src/blackgui/components/settingsmodelcomponent.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H #define BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H +#include "blackgui/settings/guisettings.h" #include namespace Ui { class CSettingsModelComponent; } @@ -33,8 +34,18 @@ namespace BlackGui //! Destructor virtual ~CSettingsModelComponent(); + //! Interval, -1 for disabled + int getBackgroundUpdaterIntervallSecs() const; + private: QScopedPointer ui; + BlackMisc::CSetting m_consolidationSetting { this, &CSettingsModelComponent::cacheChanged }; //!< consolidation time + + //! Consolidation time entered + void consolidationEntered(); + + //! Cache has been changed + void cacheChanged(); }; } // ns } // ns diff --git a/src/blackgui/components/settingsmodelcomponent.ui b/src/blackgui/components/settingsmodelcomponent.ui index ccffa59c1..cfe70c927 100644 --- a/src/blackgui/components/settingsmodelcomponent.ui +++ b/src/blackgui/components/settingsmodelcomponent.ui @@ -6,20 +6,14 @@ 0 0 - 175 + 374 28 Frame - - QFrame::StyledPanel - - - QFrame::Raised - - + 3 @@ -42,8 +36,55 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Consolidate (secs): + + + + + + + + 50 + 16777215 + + + + 4 + + + secs. + + + + + + + + + BlackGui::CLedWidget + QWidget +
blackgui/led.h
+ 1 +
+