From: Kevin Krammer Date: Fri, 2 Nov 2012 14:35:01 +0000 (+0100) Subject: Refactor input dialog attached to common base class X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8dce376fea33517d6fcd6b3b499012bd8229df9a;p=web%2Fkonrad%2FDeclarativeWidgets.git Refactor input dialog attached to common base class --- diff --git a/lib/declarativeinputdialog.cpp b/lib/declarativeinputdialog.cpp index d23aacd..244bd2f 100644 --- a/lib/declarativeinputdialog.cpp +++ b/lib/declarativeinputdialog.cpp @@ -30,7 +30,6 @@ class DeclarativeInputDialogAttached::Private {} public: - QPointer dialogParent; QString title; QString label; bool dialogAccepted; @@ -49,7 +48,7 @@ class DeclarativeInputDialogAttached::Private }; DeclarativeInputDialogAttached::DeclarativeInputDialogAttached(QObject *parent) - : QObject(parent), d(new Private) + : StaticDialogMethodAttached(parent), d(new Private) { } @@ -58,20 +57,6 @@ DeclarativeInputDialogAttached::~DeclarativeInputDialogAttached() delete d; } -void DeclarativeInputDialogAttached::setDialogParent(QObject *parent) -{ - if (parent == d->dialogParent) - return; - - d->dialogParent = parent; - emit dialogParentChanged(parent); -} - -QObject *DeclarativeInputDialogAttached::dialogParent() const -{ - return d->dialogParent; -} - void DeclarativeInputDialogAttached::setTitle(const QString &title) { if (title == d->title) @@ -233,7 +218,7 @@ QString DeclarativeInputDialogAttached::text() const double DeclarativeInputDialogAttached::getDouble() { - QWidget *parent = bestParentWindow(d->dialogParent); + QWidget *parent = bestParentWindow(); bool ok = false; const double value = d->value.canConvert() ? d->value.value() : 0.0; const double min = d->min.canConvert() ? d->min.value() : -2147483647; @@ -247,7 +232,7 @@ double DeclarativeInputDialogAttached::getDouble() int DeclarativeInputDialogAttached::getInt() { - QWidget *parent = bestParentWindow(d->dialogParent); + QWidget *parent = bestParentWindow(); bool ok = false; const int value = d->value.canConvert() ? d->value.value() : 0; const int min = d->min.canConvert() ? d->min.value() : -2147483647; @@ -261,7 +246,7 @@ int DeclarativeInputDialogAttached::getInt() QString DeclarativeInputDialogAttached::getItem(const QStringList &items) { - QWidget *parent = bestParentWindow(d->dialogParent); + QWidget *parent = bestParentWindow(); bool ok = false; const QString retVal = QInputDialog::getItem(parent, d->title, d->label, items, d->currentItem, d->itemsEditable, &ok); @@ -272,7 +257,7 @@ QString DeclarativeInputDialogAttached::getItem(const QStringList &items) QString DeclarativeInputDialogAttached::getText() { - QWidget *parent = bestParentWindow(d->dialogParent); + QWidget *parent = bestParentWindow(); bool ok = false; const QString retVal = QInputDialog::getText(parent, d->title, d->label, d->echoMode, d->text, &ok); @@ -290,27 +275,6 @@ void DeclarativeInputDialogAttached::setDialogAccepted(bool accepted) emit dialogAcceptedChanged(accepted); } -QWidget *DeclarativeInputDialogAttached::bestParentWindow(QObject *parent) const -{ - if (!parent) - parent = this->parent(); - - // if parent is a Declarative Object, search the proxied hierarchy - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - DeclarativeInputDialog::DeclarativeInputDialog(QObject *parent) : DeclarativeWidgetProxy(parent) { connectAllSignals(m_proxiedObject, this); diff --git a/lib/declarativeinputdialog_p.h b/lib/declarativeinputdialog_p.h index d2705d4..7d5a12b 100644 --- a/lib/declarativeinputdialog_p.h +++ b/lib/declarativeinputdialog_p.h @@ -24,11 +24,11 @@ #include "declarativewidgetproxy_p.h" #include "objectadaptors_p.h" +#include "staticdialogmethodattached_p.h" -class DeclarativeInputDialogAttached : public QObject +class DeclarativeInputDialogAttached : public StaticDialogMethodAttached { Q_OBJECT - Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) Q_PROPERTY(bool ok READ dialogAccepted NOTIFY dialogAcceptedChanged) @@ -49,9 +49,6 @@ class DeclarativeInputDialogAttached : public QObject DeclarativeInputDialogAttached(QObject *parent = 0); ~DeclarativeInputDialogAttached(); - void setDialogParent(QObject *parent); - QObject *dialogParent() const; - void setTitle(const QString &title); QString title() const; @@ -96,7 +93,6 @@ class DeclarativeInputDialogAttached : public QObject Q_INVOKABLE QString getText(); Q_SIGNALS: - void dialogParentChanged(QObject *parent); void titleChanged(const QString &title); void labelChanged(const QString &label); void dialogAcceptedChanged(bool accepted); @@ -115,7 +111,6 @@ class DeclarativeInputDialogAttached : public QObject private: void setDialogAccepted(bool accepted); - QWidget *bestParentWindow(QObject *parent) const; class Private; Private *const d;