Added settings to presenceplugin for interval #80
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "presencewidget.h"
|
||||
#include "presencesettingswidget.h"
|
||||
|
||||
PresencePlugin::PresencePlugin(QObject *parent) :
|
||||
ZeiterfassungPlugin(parent)
|
||||
@@ -34,3 +35,8 @@ void PresencePlugin::attachTo(MainWindow &mainWindow)
|
||||
{
|
||||
mainWindow.statusBar()->addWidget(new PresenceWidget(mainWindow));
|
||||
}
|
||||
|
||||
SettingsWidget *PresencePlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||
{
|
||||
return new PresenceSettingsWidget(settings, parent);
|
||||
}
|
||||
|
@@ -19,6 +19,8 @@ public:
|
||||
// ZeiterfassungPlugin interface
|
||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||
|
||||
virtual SettingsWidget *settingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QTranslator m_translator;
|
||||
};
|
||||
|
@@ -17,10 +17,14 @@ DEPENDPATH += $$PWD/$${PROJECT_ROOT}/zeiterfassungcorelib $$PWD/$${PROJECT_ROOT}
|
||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
||||
|
||||
HEADERS += presenceplugin.h \
|
||||
presencewidget.h
|
||||
presencewidget.h \
|
||||
presencesettings.h \
|
||||
presencesettingswidget.h
|
||||
|
||||
SOURCES += presenceplugin.cpp \
|
||||
presencewidget.cpp
|
||||
presencewidget.cpp \
|
||||
presencesettings.cpp \
|
||||
presencesettingswidget.cpp
|
||||
|
||||
FORMS +=
|
||||
|
||||
|
27
plugins/presenceplugin/presencesettings.cpp
Normal file
27
plugins/presenceplugin/presencesettings.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "presencesettings.h"
|
||||
|
||||
#include "zeiterfassungsettings.h"
|
||||
|
||||
const QString PresenceSettings::m_interval("PresencePlugin/interval");
|
||||
const int PresenceSettings::m_defaultInterval(60000);
|
||||
|
||||
PresenceSettings::PresenceSettings(ZeiterfassungSettings &settings, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int PresenceSettings::interval() const
|
||||
{
|
||||
return m_settings.value(m_interval, m_defaultInterval).toInt();
|
||||
}
|
||||
|
||||
void PresenceSettings::setInterval(int interval)
|
||||
{
|
||||
if(this->interval() != interval)
|
||||
{
|
||||
m_settings.setValue(m_interval, interval);
|
||||
Q_EMIT intervalChanged(interval);
|
||||
}
|
||||
}
|
29
plugins/presenceplugin/presencesettings.h
Normal file
29
plugins/presenceplugin/presencesettings.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef PRESENCESETTINGS_H
|
||||
#define PRESENCESETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ZeiterfassungSettings;
|
||||
|
||||
class PresenceSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
|
||||
|
||||
public:
|
||||
PresenceSettings(ZeiterfassungSettings &settings, QObject *parent = Q_NULLPTR);
|
||||
|
||||
int interval() const;
|
||||
void setInterval(int interval);
|
||||
|
||||
Q_SIGNALS:
|
||||
void intervalChanged(int interval);
|
||||
|
||||
private:
|
||||
ZeiterfassungSettings &m_settings;
|
||||
|
||||
static const QString m_interval;
|
||||
static const int m_defaultInterval;
|
||||
};
|
||||
|
||||
#endif // PRESENCESETTINGS_H
|
29
plugins/presenceplugin/presencesettingswidget.cpp
Normal file
29
plugins/presenceplugin/presencesettingswidget.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "presencesettingswidget.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QSpinBox>
|
||||
|
||||
PresenceSettingsWidget::PresenceSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||
SettingsWidget(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
auto layout = new QFormLayout(this);
|
||||
layout->setMargin(0);
|
||||
|
||||
m_spinBox = new QSpinBox(this);
|
||||
m_spinBox->setRange(0, std::numeric_limits<int>::max());
|
||||
m_spinBox->setValue(m_settings.interval());
|
||||
layout->addRow(tr("Interval(ms):"), m_spinBox);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool PresenceSettingsWidget::isValid(QString &message) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void PresenceSettingsWidget::apply()
|
||||
{
|
||||
m_settings.setInterval(m_spinBox->value());
|
||||
}
|
28
plugins/presenceplugin/presencesettingswidget.h
Normal file
28
plugins/presenceplugin/presencesettingswidget.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef PRESENCESETTINGSWIDGET_H
|
||||
#define PRESENCESETTINGSWIDGET_H
|
||||
|
||||
#include "settingswidget.h"
|
||||
|
||||
#include "presencesettings.h"
|
||||
|
||||
class QSpinBox;
|
||||
|
||||
class PresenceSettingsWidget : public SettingsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PresenceSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||
|
||||
virtual bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void apply() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
PresenceSettings m_settings;
|
||||
|
||||
QSpinBox *m_spinBox;
|
||||
};
|
||||
|
||||
#endif // PRESENCESETTINGSWIDGET_H
|
@@ -1,17 +1,17 @@
|
||||
#include "presencewidget.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QStatusBar>
|
||||
#include <QAction>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QStringBuilder>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "presencesettings.h"
|
||||
|
||||
PresenceWidget::PresenceWidget(MainWindow &mainWindow) :
|
||||
QPushButton(&mainWindow),
|
||||
m_mainWindow(mainWindow)
|
||||
@@ -27,7 +27,7 @@ PresenceWidget::PresenceWidget(MainWindow &mainWindow) :
|
||||
m_mainWindow.menuView()->addAction(m_action);
|
||||
|
||||
auto timer = new QTimer(this);
|
||||
timer->setInterval(60000);
|
||||
timer->setInterval(PresenceSettings(mainWindow.settings()).interval());
|
||||
connect(timer, &QTimer::timeout, this, &PresenceWidget::refresh);
|
||||
timer->start();
|
||||
|
||||
|
Reference in New Issue
Block a user