First working counter
This commit is contained in:
parent
80e1755a8a
commit
6264bf00ce
3 changed files with 56 additions and 18 deletions
|
@ -1,18 +1,34 @@
|
||||||
#include "counter.h"
|
#include "counter.h"
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
Counter::Counter(QObject *parent)
|
Counter::Counter(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject{parent}
|
||||||
|
, m_value{0}
|
||||||
{
|
{
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
uint Counter::counter() const
|
quint32 Counter::value() const
|
||||||
{
|
{
|
||||||
return m_counter;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Counter::setCounter(const uint counter)
|
void Counter::setValue(const quint32 value)
|
||||||
{
|
{
|
||||||
m_counter = counter;
|
m_value = value;
|
||||||
Q_EMIT counterChanged();
|
Q_EMIT valueChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Counter::increment() {
|
||||||
|
if (m_value == UINT_MAX) return;
|
||||||
|
|
||||||
|
m_value += 1;
|
||||||
|
Q_EMIT valueChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Counter::decrement() {
|
||||||
|
if (m_value == 0) return;
|
||||||
|
|
||||||
|
m_value -= 1;
|
||||||
|
Q_EMIT valueChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,21 @@
|
||||||
|
|
||||||
class Counter: public QObject {
|
class Counter: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(uint counter READ counter WRITE setCounter NOTIFY counterChanged)
|
Q_PROPERTY(uint value READ value WRITE setValue NOTIFY valueChanged)
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Counter(QObject *parent = nullptr);
|
explicit Counter(QObject *parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] uint counter() const;
|
[[nodiscard]] quint32 value() const;
|
||||||
void setCounter(const uint counter);
|
void setValue(const quint32 value);
|
||||||
|
|
||||||
|
Q_INVOKABLE void increment();
|
||||||
|
Q_INVOKABLE void decrement();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void counterChanged();
|
void valueChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint m_counter;
|
quint32 m_value;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick
|
||||||
import QtQuick.Controls as Controls
|
import QtQuick.Controls as Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import org.kde.kirigami as Kirigami
|
import org.kde.kirigami as Kirigami
|
||||||
|
import fr.mrdev023.tutorial_kirigami2
|
||||||
|
|
||||||
Kirigami.ApplicationWindow {
|
Kirigami.ApplicationWindow {
|
||||||
id: root
|
id: root
|
||||||
|
@ -23,9 +24,26 @@ Kirigami.ApplicationWindow {
|
||||||
pageStack.initialPage: Kirigami.ScrollablePage {
|
pageStack.initialPage: Kirigami.ScrollablePage {
|
||||||
title: i18nc("@title", "Main Page")
|
title: i18nc("@title", "Main Page")
|
||||||
|
|
||||||
actions: [
|
Kirigami.FlexColumn {
|
||||||
]
|
anchors.fill: parent
|
||||||
|
|
||||||
Item {}
|
Controls.Label {
|
||||||
|
text: counter.value
|
||||||
|
}
|
||||||
|
|
||||||
|
Controls.Button {
|
||||||
|
text: i18n("-")
|
||||||
|
onClicked: counter.decrement()
|
||||||
|
}
|
||||||
|
|
||||||
|
Controls.Button {
|
||||||
|
text: i18n("+")
|
||||||
|
onClicked: counter.increment()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Counter {
|
||||||
|
id: counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue