Ref T28, settings for updater

This commit is contained in:
Klaus Basan
2017-05-03 02:23:55 +02:00
committed by Mathew Sutcliffe
parent f12b69bb87
commit f4af5e6cc1
3 changed files with 100 additions and 8 deletions

View File

@@ -10,6 +10,12 @@
#include "settingsmodelcomponent.h" #include "settingsmodelcomponent.h"
#include "ui_settingsmodelcomponent.h" #include "ui_settingsmodelcomponent.h"
#include "blackmisc/logmessage.h"
#include <QValidator>
using namespace BlackMisc;
using namespace BlackGui::Settings;
namespace BlackGui namespace BlackGui
{ {
namespace Components namespace Components
@@ -19,9 +25,43 @@ namespace BlackGui
ui(new Ui::CSettingsModelComponent) ui(new Ui::CSettingsModelComponent)
{ {
ui->setupUi(this); 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() 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
} // ns } // ns

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H #ifndef BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H
#define BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H #define BLACKGUI_COMPONENTS_SETTINGSMODELCOMPONENT_H
#include "blackgui/settings/guisettings.h"
#include <QFrame> #include <QFrame>
namespace Ui { class CSettingsModelComponent; } namespace Ui { class CSettingsModelComponent; }
@@ -33,8 +34,18 @@ namespace BlackGui
//! Destructor //! Destructor
virtual ~CSettingsModelComponent(); virtual ~CSettingsModelComponent();
//! Interval, -1 for disabled
int getBackgroundUpdaterIntervallSecs() const;
private: private:
QScopedPointer<Ui::CSettingsModelComponent> ui; QScopedPointer<Ui::CSettingsModelComponent> ui;
BlackMisc::CSetting<BlackGui::Settings::TBackgroundConsolidation> m_consolidationSetting { this, &CSettingsModelComponent::cacheChanged }; //!< consolidation time
//! Consolidation time entered
void consolidationEntered();
//! Cache has been changed
void cacheChanged();
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -6,20 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>175</width> <width>374</width>
<height>28</height> <height>28</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Frame</string> <string>Frame</string>
</property> </property>
<property name="frameShape"> <layout class="QHBoxLayout" name="hl_SettingsModelComponent">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_Settings">
<property name="leftMargin"> <property name="leftMargin">
<number>3</number> <number>3</number>
</property> </property>
@@ -42,8 +36,55 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="hs_SetiingsModelComponent">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lbl_Consolidate">
<property name="text">
<string>Consolidate (secs):</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_ConsolidateSecs">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="maxLength">
<number>4</number>
</property>
<property name="placeholderText">
<string>secs.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="comp_Led" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>BlackGui::CLedWidget</class>
<extends>QWidget</extends>
<header>blackgui/led.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>