From 38f74bb70248610bc4cd1cd151e0bf5165f0b75c Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Wed, 9 Jan 2013 11:46:53 +0100 Subject: [PATCH] Port button group --- lib/declarativebuttongroup.cpp | 29 ------------ lib/declarativebuttongroup_p.h | 36 --------------- lib/declarativebuttongroupextension.cpp | 72 +++++++++++++++++++++++++++++++ lib/declarativebuttongroupextension_p.h | 55 +++++++++++++++++++++++ lib/lib.pro | 4 +- lib/objectadaptors.cpp | 47 -------------------- lib/objectadaptors_p.h | 20 --------- 7 files changed, 129 insertions(+), 134 deletions(-) delete mode 100644 lib/declarativebuttongroup.cpp delete mode 100644 lib/declarativebuttongroup_p.h create mode 100644 lib/declarativebuttongroupextension.cpp create mode 100644 lib/declarativebuttongroupextension_p.h diff --git a/lib/declarativebuttongroup.cpp b/lib/declarativebuttongroup.cpp deleted file mode 100644 index 981f1db..0000000 --- a/lib/declarativebuttongroup.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "declarativebuttongroup_p.h" - -DeclarativeButtonGroup::DeclarativeButtonGroup(QObject *parent) - : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeButtonGroup, ButtonGroup) diff --git a/lib/declarativebuttongroup_p.h b/lib/declarativebuttongroup_p.h deleted file mode 100644 index 18564dc..0000000 --- a/lib/declarativebuttongroup_p.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Krammer, krake@kdab.com - Author: Tobias Koenig, tokoe@kdab.com - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef DECLARATIVEBUTTONGROUP_P_H -#define DECLARATIVEBUTTONGROUP_P_H - -#include "declarativeobjectproxy_p.h" - -#include "objectadaptors_p.h" - -class DeclarativeButtonGroup : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - explicit DeclarativeButtonGroup(QObject *parent = 0); -}; - -#endif diff --git a/lib/declarativebuttongroupextension.cpp b/lib/declarativebuttongroupextension.cpp new file mode 100644 index 0000000..994c83e --- /dev/null +++ b/lib/declarativebuttongroupextension.cpp @@ -0,0 +1,72 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativebuttongroupextension_p.h" + +#include +#include + +DeclarativeButtonGroupExtension::DeclarativeButtonGroupExtension(QObject *parent) + : DeclarativeObjectExtension(parent) +{ +} + +void DeclarativeButtonGroupExtension::setButtons(const QVariantList &buttons) +{ + if (m_buttons == buttons) + return; + + // First remove the old buttons ... + foreach (const QVariant &variant, m_buttons) { + QObject *object = variant.value(); + if (object) { + QAbstractButton *button = qobject_cast(object); + if (button) + buttonGroup()->removeButton(button); + } + } + + m_buttons = buttons; + + // ... then add the new ones + foreach (const QVariant &variant, m_buttons) { + QObject *object = variant.value(); + if (object) { + QAbstractButton *button = qobject_cast(object); + if (button) + buttonGroup()->addButton(button); + } + } + + emit buttonsChanged(); +} + +QVariantList DeclarativeButtonGroupExtension::buttons() const +{ + return m_buttons; +} + +QButtonGroup *DeclarativeButtonGroupExtension::buttonGroup() const +{ + QButtonGroup *buttonGroup = qobject_cast(extendedObject()); + Q_ASSERT(buttonGroup); + + return buttonGroup; +} diff --git a/lib/declarativebuttongroupextension_p.h b/lib/declarativebuttongroupextension_p.h new file mode 100644 index 0000000..98b0254 --- /dev/null +++ b/lib/declarativebuttongroupextension_p.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEBUTTONGROUPEXTENSION_P_H +#define DECLARATIVEBUTTONGROUPEXTENSION_P_H + +#include "declarativeobjectextension.h" + +#include + +class QButtonGroup; + +class DeclarativeButtonGroupExtension : public DeclarativeObjectExtension +{ + Q_OBJECT + + Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) + + // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class + Q_PROPERTY(QDeclarativeListProperty data READ data DESIGNABLE false) + + Q_CLASSINFO("DefaultProperty", "data") + + public: + explicit DeclarativeButtonGroupExtension(QObject *parent = 0); + + Q_SIGNALS: + void buttonsChanged(); + + private: + void setButtons(const QVariantList &buttons); + QVariantList buttons() const; + QButtonGroup *buttonGroup() const; + + QVariantList m_buttons; +}; + +#endif diff --git a/lib/lib.pro b/lib/lib.pro index d998080..3423c4a 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -9,7 +9,7 @@ HEADERS = \ declarativeactionitem_p.h \ declarativeaction_p.h \ declarativeboxlayout_p.h \ - declarativebuttongroup_p.h \ + declarativebuttongroupextension_p.h \ declarativecalendarwidget_p.h \ declarativecolordialog_p.h \ declarativecolumnview_p.h \ @@ -75,7 +75,7 @@ SOURCES = \ declarativeaction.cpp \ declarativeactionitem.cpp \ declarativeboxlayout.cpp \ - declarativebuttongroup.cpp \ + declarativebuttongroupextension.cpp \ declarativecalendarwidget.cpp \ declarativecolordialog.cpp \ declarativecolumnview.cpp \ diff --git a/lib/objectadaptors.cpp b/lib/objectadaptors.cpp index 14ccc49..3efd3aa 100644 --- a/lib/objectadaptors.cpp +++ b/lib/objectadaptors.cpp @@ -76,53 +76,6 @@ QVariant ActionItem::qmlAction() const return m_action; } -// ButtonGroup -ButtonGroup::ButtonGroup(QObject *parent) - : QButtonGroup(parent) -{ -} - -void ButtonGroup::setButtons(const QVariantList &buttons) -{ - if (m_buttons == buttons) - return; - - // First remove the old buttons ... - foreach (const QVariant &variant, m_buttons) { - QObject *object = variant.value(); - if (object) { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QAbstractButton *button = qobject_cast(declarativeObject->object()); - if (button) - QButtonGroup::removeButton(button); - } - } - } - - m_buttons = buttons; - - // ... then add the new ones - foreach (const QVariant &variant, m_buttons) { - QObject *object = variant.value(); - if (object) { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QAbstractButton *button = qobject_cast(declarativeObject->object()); - if (button) - QButtonGroup::addButton(button); - } - } - } - - emit buttonsChanged(); -} - -QVariantList ButtonGroup::buttons() const -{ - return m_buttons; -} - // ColumnView ColumnView::ColumnView(QWidget *parent) : QColumnView(parent) diff --git a/lib/objectadaptors_p.h b/lib/objectadaptors_p.h index af2bd26..e19d9e1 100644 --- a/lib/objectadaptors_p.h +++ b/lib/objectadaptors_p.h @@ -22,7 +22,6 @@ #define OBJECTADAPTORS_P_H #include -#include #include #include #include @@ -56,25 +55,6 @@ class ActionItem : public QObject QAction* m_qAction; }; -class ButtonGroup : public QButtonGroup -{ - Q_OBJECT - - Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) - - public: - explicit ButtonGroup(QObject *parent = 0); - - Q_SIGNALS: - void buttonsChanged(); - - private: - void setButtons(const QVariantList &buttons); - QVariantList buttons() const; - - QVariantList m_buttons; -}; - class ColumnView : public QColumnView { Q_OBJECT -- 1.7.2.5