Skip to content

Commit 7bd4eb9

Browse files
committed
Rework DeclarativePushButton into an extension class
1 parent 4e5d436 commit 7bd4eb9

6 files changed

+138
-19
lines changed

src/declarativepushbutton.cpp renamed to src/declarativeabstractbuttonextension.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
declarativepushbutton.cpp
2+
declarativeabstractbuttonextension.cpp
33
44
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.
55
6-
Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
6+
Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
77
Author: Lova Widmark <[email protected]>
88
99
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in
@@ -25,8 +25,9 @@
2525
along with this program. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
#include "declarativepushbutton_p.h"
28+
#include "declarativeabstractbuttonextension_p.h"
2929

30-
DeclarativePushButton::DeclarativePushButton(QWidget *parent) : QPushButton(parent)
30+
DeclarativeAbstractButtonExtension::DeclarativeAbstractButtonExtension(QObject *parent)
31+
: DeclarativeWidgetExtension(parent)
3132
{
3233
}

src/declarativepushbutton_p.h renamed to src/declarativeabstractbuttonextension_p.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
declarativepushbutton_p.h
2+
declarativeabstractbuttonextension_p.h
33
44
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.
55
6-
Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
6+
Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
77
Author: Lova Widmark <[email protected]>
88
99
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in
@@ -25,18 +25,17 @@
2525
along with this program. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
#ifndef DECLARATIVEPUSHBUTTON_P_H
29-
#define DECLARATIVEPUSHBUTTON_P_H
28+
#ifndef DECLARATIVEABSTRACTBUTTONEXTENSION_P_H
29+
#define DECLARATIVEABSTRACTBUTTONEXTENSION_P_H
3030

31-
#include <QPushButton>
31+
#include "declarativewidgetextension.h"
3232

33-
class DeclarativePushButton : public QPushButton
33+
class DeclarativeAbstractButtonExtension : public DeclarativeWidgetExtension
3434
{
35-
Q_OBJECT
36-
Q_PROPERTY(bool isDefault READ isDefault WRITE setDefault)
35+
Q_OBJECT
3736

38-
public:
39-
explicit DeclarativePushButton(QWidget *parent = 0);
37+
public:
38+
explicit DeclarativeAbstractButtonExtension(QObject *parent = Q_NULLPTR);
4039
};
4140

42-
#endif // DECLARATIVEPUSHBUTTON_P_H
41+
#endif // DECLARATIVEABSTRACTBUTTONEXTENSION_P_H
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
declarativepushbuttonextension.cpp
3+
4+
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.
5+
6+
Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
7+
Author: Lova Widmark <[email protected]>
8+
9+
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in
10+
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software.
11+
12+
Contact [email protected] if any conditions of this licensing are not clear to you.
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#include "declarativepushbuttonextension_p.h"
29+
30+
#include <QPushButton>
31+
32+
DeclarativePushButtonExtension::DeclarativePushButtonExtension(QObject *parent)
33+
: DeclarativeAbstractButtonExtension(parent)
34+
{
35+
}
36+
37+
bool DeclarativePushButtonExtension::isDefault() const
38+
{
39+
return pushButton()->isDefault();
40+
}
41+
42+
void DeclarativePushButtonExtension::setIsDefault(bool isDefault)
43+
{
44+
QPushButton *button = pushButton();
45+
46+
if (button->isDefault() == isDefault)
47+
return;
48+
49+
button->setDefault(isDefault);
50+
51+
emit isDefaultChanged();
52+
}
53+
54+
QPushButton *DeclarativePushButtonExtension::pushButton() const
55+
{
56+
QPushButton *pushButton = qobject_cast<QPushButton*>(extendedObject());
57+
58+
Q_ASSERT(pushButton);
59+
60+
return pushButton;
61+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
declarativepushbuttonextension_p.h
3+
4+
This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML.
5+
6+
Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
7+
Author: Lova Widmark <[email protected]>
8+
9+
Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in
10+
accordance with DeclarativeWidgets Commercial License Agreement provided with the Software.
11+
12+
Contact [email protected] if any conditions of this licensing are not clear to you.
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#ifndef DECLARATIVEPUSHBUTTONEXTENSION_P_H
29+
#define DECLARATIVEPUSHBUTTONEXTENSION_P_H
30+
31+
#include "declarativeabstractbuttonextension_p.h"
32+
33+
QT_BEGIN_NAMESPACE
34+
class QPushButton;
35+
QT_END_NAMESPACE
36+
37+
class DeclarativePushButtonExtension : public DeclarativeAbstractButtonExtension
38+
{
39+
Q_OBJECT
40+
41+
Q_PROPERTY(bool isDefault READ isDefault WRITE setIsDefault NOTIFY isDefaultChanged)
42+
43+
public:
44+
explicit DeclarativePushButtonExtension(QObject *parent = Q_NULLPTR);
45+
46+
bool isDefault() const;
47+
void setIsDefault(bool isDefault);
48+
49+
Q_SIGNALS:
50+
void isDefaultChanged();
51+
52+
private:
53+
QPushButton *pushButton() const;
54+
};
55+
56+
#endif // DECLARATIVEPUSHBUTTONEXTENSION_P_H

src/declarativewidgets_plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "declarativeloaderwidget_p.h"
5050
#include "declarativemessagebox_p.h"
5151
#include "declarativepixmap_p.h"
52+
#include "declarativepushbuttonextension_p.h"
5253
#include "declarativeqmlcontext_p.h"
5354
#include "declarativequickwidgetextension_p.h"
5455
#include "declarativeseparator_p.h"
@@ -70,7 +71,6 @@
7071
#include "scrollareawidgetcontainer_p.h"
7172
#include "stackedwidgetwidgetcontainer_p.h"
7273
#include "toolbarwidgetcontainer_p.h"
73-
#include "declarativepushbutton_p.h"
7474

7575
#include <QAbstractItemDelegate>
7676
#include <QButtonGroup>
@@ -186,7 +186,7 @@ void ExtensionpluginPlugin::registerTypes(const char *uri)
186186
qmlRegisterExtendedType<DeclarativeMessageBox, DeclarativeWidgetExtension>(uri, 1, 0, "MessageBox");
187187
qmlRegisterExtendedType<QPlainTextEdit, DeclarativeWidgetExtension>(uri, 1, 0, "PlainTextEdit");
188188
qmlRegisterExtendedType<QProgressBar, DeclarativeWidgetExtension>(uri, 1, 0, "ProgressBar");
189-
qmlRegisterExtendedType<DeclarativePushButton, DeclarativeWidgetExtension>(uri, 1, 0, "PushButton");
189+
qmlRegisterExtendedType<QPushButton, DeclarativePushButtonExtension>(uri, 1, 0, "PushButton");
190190
qmlRegisterExtendedType<QRadioButton, DeclarativeWidgetExtension>(uri, 1, 0, "RadioButton");
191191
qmlRegisterExtendedType<QScrollArea, DeclarativeContainerWidgetExtension<ScrollAreaWidgetContainer> >(uri, 1, 0, "ScrollArea");
192192
qmlRegisterExtendedType<QScrollBar, DeclarativeWidgetExtension>(uri, 1, 0, "ScrollBar");

src/src.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ HEADERS = \
8787
toolbarwidgetcontainer_p.h \
8888
widgetcontainerinterface_p.h \
8989
declarativesizepolicy_p.h \
90-
declarativepushbutton_p.h
90+
declarativeabstractbuttonextension_p.h \
91+
declarativepushbuttonextension_p.h
9192

9293
SOURCES = \
9394
abstractdeclarativeobject.cpp \
@@ -139,4 +140,5 @@ SOURCES = \
139140
staticdialogmethodattached.cpp \
140141
toolbarwidgetcontainer.cpp \
141142
declarativesizepolicy.cpp \
142-
declarativepushbutton.cpp
143+
declarativeabstractbuttonextension.cpp \
144+
declarativepushbuttonextension.cpp

0 commit comments

Comments
 (0)