[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: KConfigDialogManager without Q3SqlPropertyMap
From: Szombathelyi "György" <gyurco () freemail ! hu>
Date: 2006-01-28 17:12:16
Message-ID: 200601281812.16634.gyurco () freemail ! hu
[Download RAW message or body]
And here's an improved patch, with api docs. I'll commit tomorrow if there
will no objections.
Bye,
György
____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol
Probald ki most! http://www.freestart.hu
["q3sql.diff" (text/x-diff)]
Index: kdecore/kapplication.h
===================================================================
--- kdecore/kapplication.h (revision 503162)
+++ kdecore/kapplication.h (working copy)
@@ -462,12 +462,6 @@
};
#endif
- /**
- * Install a Qt SQL property map with entries for all KDE widgets
- * Call this in any application using KDE widgets in QSqlForm or QDataView.
- */
- static void installKDEPropertyMap();
-
public Q_SLOTS:
/**
* Tells KApplication about one more operation that should be finished
Index: kdecore/kapplication.cpp
===================================================================
--- kdecore/kapplication.cpp (revision 503162)
+++ kdecore/kapplication.cpp (working copy)
@@ -40,9 +40,6 @@
#include <qtimer.h>
#include <qtooltip.h>
#include <qwidget.h>
-#ifndef QT_NO_SQL
-#include <q3sqlpropertymap.h> // no equivilant in Qt4
-#endif
#include <QList>
@@ -1645,44 +1642,6 @@
emit settingsChanged(arg);
}
-void KApplication::installKDEPropertyMap()
-{
-#ifndef QT_NO_SQL
- static bool installed = false;
- if (installed) return;
- installed = true;
- /**
- * If you are adding a widget that was missing please
- * make sure to also add it to KConfigDialogManager's retrieveSettings()
- * function.
- * Thanks.
- */
- // QSqlPropertyMap takes ownership of the new default map.
- Q3SqlPropertyMap *kdeMap = new Q3SqlPropertyMap;
- kdeMap->insert( "KColorButton", "color" );
- kdeMap->insert( "KComboBox", "currentItem" );
- kdeMap->insert( "KDatePicker", "date" );
- kdeMap->insert( "KDateWidget", "date" );
- kdeMap->insert( "KDateTimeWidget", "dateTime" );
- kdeMap->insert( "KEditListBox", "items" );
- kdeMap->insert( "KFontCombo", "family" );
- kdeMap->insert( "KFontRequester", "font" );
- kdeMap->insert( "KFontChooser", "font" );
- kdeMap->insert( "KHistoryCombo", "currentItem" );
- kdeMap->insert( "KListBox", "currentItem" );
- kdeMap->insert( "KLineEdit", "text" );
- kdeMap->insert( "KRestrictedLine", "text" );
- kdeMap->insert( "KTextBrowser", "source" );
- kdeMap->insert( "KTextEdit", "text" );
- kdeMap->insert( "KUrlRequester", "url" );
- kdeMap->insert( "KPasswordEdit", "password" );
- kdeMap->insert( "KIntNumInput", "value" );
- kdeMap->insert( "KIntSpinBox", "value" );
- kdeMap->insert( "KDoubleNumInput", "value" );
- Q3SqlPropertyMap::installDefaultMap( kdeMap );
-#endif
-}
-
QByteArray KApplication::launcher()
{
return "klauncher";
Index: kdeui/kconfigdialogmanager.h
===================================================================
--- kdeui/kconfigdialogmanager.h (revision 503162)
+++ kdeui/kconfigdialogmanager.h (working copy)
@@ -21,15 +21,13 @@
#ifndef KCONFIGDIALOGMANAGER_H
#define KCONFIGDIALOGMANAGER_H
-#include <qobject.h>
-#include <qmap.h>
-#include <q3ptrlist.h>
+#include <QObject>
+#include <QMap>
#include "kdelibs_export.h"
class KConfigSkeleton;
class KConfigSkeletonItem;
class QWidget;
-class Q3SqlPropertyMap;
/**
* @short Provides a means of automatically retrieving,
@@ -46,12 +44,10 @@
* "kcfg_" prefix. For example a widget named "kcfg_MyOption" would be
* associated to the configuration entry "MyOption".
*
- * KConfigDialogManager uses the QSqlPropertyMap class to determine if it can do
- * anything to a widget. Note that KConfigDialogManager doesn't require a
- * database, it simply uses the functionality that is built into the
- * QSqlPropertyMap class. New widgets can be added to the map using
- * QSqlPropertyMap::installDefaultMap(). Note that you can't just add any
- * class. The class must have a matching Q_PROPERTY(...) macro defined.
+ * New widgets can be added to the map using the static functions propertyMap() and
+ * changedMap(). Note that you can't just add any class. The class must have a
+ * matching Q_PROPERTY(...) macro defined, and a signal which emitted when the
+ * property changed.
*
* For example (note that KColorButton is already added and it doesn't need to
* manually added):
@@ -60,17 +56,18 @@
* \code
* Q_PROPERTY( QColor color READ color WRITE setColor )
* \endcode
+ * and signal:
+ * \code
+ * void changed( const QColor &newColor );
+ * \endcode
*
- * To add KColorButton the following code would be inserted in the main.
+ * To add KColorButton the following code would be inserted in the main:
*
* \code
- * kapp->installKDEPropertyMap();
- * QSqlPropertyMap *map = QSqlPropertyMap::defaultMap();
- * map->insert("KColorButton", "color");
+ * KConfigDialogManager::propertyMap()->insert("KColorButton", "color");
+ * KConfigDialogManager::changedMap()->insert("KColorButton", SIGNAL(changed(const \
QColor &)));
* \endcode
*
- * If you add a new widget to the QSqlPropertyMap and wish to be notified when
- * it is modified you should add its signal using addWidgetChangedSignal().
* @since 3.2
* @author Benjamin C Meyer <ben+kdelibs at meyerhome dot net>
@@ -139,6 +136,16 @@
*/
bool isDefault();
+ /**
+ * Retrieve the property map
+ */
+ static QMap<QByteArray, QByteArray> *propertyMap();
+
+ /**
+ * Retrieve the widget change map
+ */
+ static QMap<QString, QByteArray> *changedMap();
+
public Q_SLOTS:
/**
* Traverse the specified widgets, saving the settings of all known
@@ -202,6 +209,12 @@
*/
void setupWidget(QWidget *widget, KConfigSkeletonItem *item);
+ /**
+ * Initializes the property maps
+ */
+ static void initMaps();
+
+
protected:
/**
* KConfigSkeleton object used to store settings
@@ -213,23 +226,13 @@
*/
QWidget *m_dialog;
- /**
- * Pointer to the property map for easy access.
- */
- Q3SqlPropertyMap *propertyMap;
-
- /**
- * Map of the classes and the signals that they emit when changed.
- */
- QMap<QString, QByteArray> changedMap;
-
+
private:
class Private;
/**
* KConfigDialogManager Private class.
*/
Private *d;
-
};
#endif // KCONFIGDIALOGMANAGER_H
Index: kdeui/kconfigdialogmanager.cpp
===================================================================
--- kdeui/kconfigdialogmanager.cpp (revision 503162)
+++ kdeui/kconfigdialogmanager.cpp (working copy)
@@ -21,23 +21,27 @@
#include "kconfigdialogmanager.h"
-#include <q3buttongroup.h>
-#include <qcombobox.h>
-#include <qlabel.h>
-#include <qmetaobject.h>
-#include <qobject.h>
-#include <q3sqlpropertymap.h>
-#include <qtimer.h>
+#include <Q3ButtonGroup>
+#include <QComboBox>
+#include <QLabel>
+#include <QMetaObject>
+#include <QTimer>
#include <QRadioButton>
+#include <QHash>
-#include <kapplication.h>
#include <kconfigskeleton.h>
#include <kdebug.h>
#include <kglobal.h>
-#include <QHash>
+#include <kstaticdeleter.h>
#include <assert.h>
+static QMap<QByteArray, QByteArray> *s_propertyMap = 0;
+static QMap<QString, QByteArray> *s_changedMap = 0;
+
+static KStaticDeleter< QMap<QByteArray, QByteArray> > s_propertyMapDeleter;
+static KStaticDeleter< QMap<QString, QByteArray> > s_changedMapDeleter;
+
class KConfigDialogManager::Private {
public:
@@ -47,6 +51,7 @@
QHash<QString, QWidget *> knownWidget;
QHash<QString, QWidget *> buddyWidget;
bool insideGroupBox;
+ bool trackChanges;
};
KConfigDialogManager::KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf)
@@ -54,9 +59,6 @@
{
d = new Private();
- kapp->installKDEPropertyMap();
- propertyMap = Q3SqlPropertyMap::defaultMap();
-
init(true);
}
@@ -65,59 +67,128 @@
delete d;
}
-void KConfigDialogManager::init(bool trackChanges)
+void KConfigDialogManager::initMaps()
{
- if(trackChanges)
+ if ( s_propertyMap == 0 ) {
+ s_propertyMapDeleter.setObject( s_propertyMap, new QMap<QByteArray,QByteArray> \
); +
+ //Qt
+ s_propertyMap->insert( "Q3DateEdit", "date" );
+ s_propertyMap->insert( "Q3DateTimeEdit", "dateTime" );
+ s_propertyMap->insert( "Q3ListBox", "currentItem" );
+ s_propertyMap->insert( "Q3TimeEdit", "time" );
+ s_propertyMap->insert( "QAbstractButton", "text" );
+ s_propertyMap->insert( "QCheckBox", "checked" );
+ s_propertyMap->insert( "QRadioButton", "checked" );
+ s_propertyMap->insert( "QComboBox", "currentIndex" );
+ s_propertyMap->insert( "QDateTimeEdit", "dateTime" );
+ s_propertyMap->insert( "QDial", "value" );
+ s_propertyMap->insert( "QLabel", "text" );
+ s_propertyMap->insert( "QLCDNumber", "value" );
+ s_propertyMap->insert( "QLineEdit", "text" );
+ s_propertyMap->insert( "QPushButton", "text" );
+ s_propertyMap->insert( "QScrollBar", "value" );
+ s_propertyMap->insert( "QSlider", "value" );
+ s_propertyMap->insert( "QSpinBox", "value" );
+ s_propertyMap->insert( "QTabBar", "currentTab" );
+ s_propertyMap->insert( "QTabWidget", "currentPage" );
+ s_propertyMap->insert( "QTextBrowser", "source" );
+ s_propertyMap->insert( "QTextEdit", "text" );
+ s_propertyMap->insert( "QGroupBox", "checked" );
+
+ //KDE
+ s_propertyMap->insert( "KColorButton", "color" );
+ s_propertyMap->insert( "KComboBox", "currentIndex" );
+ s_propertyMap->insert( "KDatePicker", "date" );
+ s_propertyMap->insert( "KDateWidget", "date" );
+ s_propertyMap->insert( "KDateTimeWidget", "dateTime" );
+ s_propertyMap->insert( "KEditListBox", "items" );
+ s_propertyMap->insert( "KFontCombo", "family" );
+ s_propertyMap->insert( "KFontRequester", "font" );
+ s_propertyMap->insert( "KFontChooser", "font" );
+ s_propertyMap->insert( "KHistoryCombo", "currentItem" );
+ s_propertyMap->insert( "KListBox", "currentItem" );
+ s_propertyMap->insert( "KLineEdit", "text" );
+ s_propertyMap->insert( "KRestrictedLine", "text" );
+ s_propertyMap->insert( "KTextBrowser", "source" );
+ s_propertyMap->insert( "KTextEdit", "text" );
+ s_propertyMap->insert( "KUrlRequester", "url" );
+ s_propertyMap->insert( "KPasswordEdit", "password" );
+ s_propertyMap->insert( "KIntNumInput", "value" );
+ s_propertyMap->insert( "KIntSpinBox", "value" );
+ s_propertyMap->insert( "KDoubleNumInput", "value" );
+ }
+
+ if( s_changedMap == 0 )
{
+ s_changedMapDeleter.setObject( s_changedMap, new QMap<QString,QByteArray> );
// QT
- changedMap.insert("QButton", SIGNAL(stateChanged(int)));
- changedMap.insert("QCheckBox", SIGNAL(stateChanged(int)));
- changedMap.insert("QPushButton", SIGNAL(stateChanged(int)));
- changedMap.insert("QRadioButton", SIGNAL(toggled(bool)));
+ s_changedMap->insert("QButton", SIGNAL(stateChanged(int)));
+ s_changedMap->insert("QCheckBox", SIGNAL(stateChanged(int)));
+ s_changedMap->insert("QPushButton", SIGNAL(stateChanged(int)));
+ s_changedMap->insert("QRadioButton", SIGNAL(toggled(bool)));
// We can only store one thing, so you can't have
// a ButtonGroup that is checkable.
- changedMap.insert("QButtonGroup", SIGNAL(clicked(int)));
- changedMap.insert("QGroupBox", SIGNAL(toggled(bool)));
- changedMap.insert("QComboBox", SIGNAL(activated (int)));
+ s_changedMap->insert("QButtonGroup", SIGNAL(clicked(int)));
+ s_changedMap->insert("QGroupBox", SIGNAL(toggled(bool)));
+ s_changedMap->insert("QComboBox", SIGNAL(activated (int)));
//qsqlproperty map doesn't store the text, but the value!
- //changedMap.insert("QComboBox", SIGNAL(textChanged(const QString &)));
- changedMap.insert("QDateEdit", SIGNAL(valueChanged(const QDate &)));
- changedMap.insert("QDateTimeEdit", SIGNAL(valueChanged(const QDateTime &)));
- changedMap.insert("QDial", SIGNAL(valueChanged (int)));
- changedMap.insert("QLineEdit", SIGNAL(textChanged(const QString &)));
- changedMap.insert("QSlider", SIGNAL(valueChanged(int)));
- changedMap.insert("QSpinBox", SIGNAL(valueChanged(int)));
- changedMap.insert("QTimeEdit", SIGNAL(valueChanged(const QTime &)));
- changedMap.insert("QTextEdit", SIGNAL(textChanged()));
- changedMap.insert("QTextBrowser", SIGNAL(sourceChanged(const QString &)));
- changedMap.insert("QMultiLineEdit", SIGNAL(textChanged()));
- changedMap.insert("QListBox", SIGNAL(selectionChanged()));
- changedMap.insert("QTabWidget", SIGNAL(currentChanged(QWidget *)));
+ //s_changedMap->insert("QComboBox", SIGNAL(textChanged(const QString &)));
+ s_changedMap->insert("QDateEdit", SIGNAL(valueChanged(const QDate &)));
+ s_changedMap->insert("QDateTimeEdit", SIGNAL(valueChanged(const QDateTime &)));
+ s_changedMap->insert("QDial", SIGNAL(valueChanged (int)));
+ s_changedMap->insert("QLineEdit", SIGNAL(textChanged(const QString &)));
+ s_changedMap->insert("QSlider", SIGNAL(valueChanged(int)));
+ s_changedMap->insert("QSpinBox", SIGNAL(valueChanged(int)));
+ s_changedMap->insert("QTimeEdit", SIGNAL(valueChanged(const QTime &)));
+ s_changedMap->insert("QTextEdit", SIGNAL(textChanged()));
+ s_changedMap->insert("QTextBrowser", SIGNAL(sourceChanged(const QString &)));
+ s_changedMap->insert("QMultiLineEdit", SIGNAL(textChanged()));
+ s_changedMap->insert("QListBox", SIGNAL(selectionChanged()));
+ s_changedMap->insert("QTabWidget", SIGNAL(currentChanged(QWidget *)));
// KDE
- changedMap.insert( "KComboBox", SIGNAL(activated (int)));
- changedMap.insert( "KFontCombo", SIGNAL(activated (int)));
- changedMap.insert( "KFontRequester", SIGNAL(fontSelected(const QFont &)));
- changedMap.insert( "KFontChooser", SIGNAL(fontSelected(const QFont &)));
- changedMap.insert( "KHistoryCombo", SIGNAL(activated (int)));
+ s_changedMap->insert( "KComboBox", SIGNAL(activated (int)));
+ s_changedMap->insert( "KFontCombo", SIGNAL(activated (int)));
+ s_changedMap->insert( "KFontRequester", SIGNAL(fontSelected(const QFont &)));
+ s_changedMap->insert( "KFontChooser", SIGNAL(fontSelected(const QFont &)));
+ s_changedMap->insert( "KHistoryCombo", SIGNAL(activated (int)));
- changedMap.insert( "KColorButton", SIGNAL(changed(const QColor &)));
- changedMap.insert( "KDatePicker", SIGNAL(dateSelected (QDate)));
- changedMap.insert( "KDateWidget", SIGNAL(changed (QDate)));
- changedMap.insert( "KDateTimeWidget", SIGNAL(valueChanged (const QDateTime &)));
- changedMap.insert( "KEditListBox", SIGNAL(changed()));
- changedMap.insert( "KListBox", SIGNAL(selectionChanged()));
- changedMap.insert( "KLineEdit", SIGNAL(textChanged(const QString &)));
- changedMap.insert( "KPasswordEdit", SIGNAL(textChanged(const QString &)));
- changedMap.insert( "KRestrictedLine", SIGNAL(textChanged(const QString &)));
- changedMap.insert( "KTextBrowser", SIGNAL(sourceChanged(const QString &)));
- changedMap.insert( "KTextEdit", SIGNAL(textChanged()));
- changedMap.insert( "KUrlRequester", SIGNAL(textChanged (const QString& )));
- changedMap.insert( "KIntNumInput", SIGNAL(valueChanged (int)));
- changedMap.insert( "KIntSpinBox", SIGNAL(valueChanged (int)));
- changedMap.insert( "KDoubleNumInput", SIGNAL(valueChanged (double)));
+ s_changedMap->insert( "KColorButton", SIGNAL(changed(const QColor &)));
+ s_changedMap->insert( "KDatePicker", SIGNAL(dateSelected (QDate)));
+ s_changedMap->insert( "KDateWidget", SIGNAL(changed (QDate)));
+ s_changedMap->insert( "KDateTimeWidget", SIGNAL(valueChanged (const QDateTime \
&))); + s_changedMap->insert( "KEditListBox", SIGNAL(changed()));
+ s_changedMap->insert( "KListBox", SIGNAL(selectionChanged()));
+ s_changedMap->insert( "KLineEdit", SIGNAL(textChanged(const QString &)));
+ s_changedMap->insert( "KPasswordEdit", SIGNAL(textChanged(const QString &)));
+ s_changedMap->insert( "KRestrictedLine", SIGNAL(textChanged(const QString &)));
+ s_changedMap->insert( "KTextBrowser", SIGNAL(sourceChanged(const QString &)));
+ s_changedMap->insert( "KTextEdit", SIGNAL(textChanged()));
+ s_changedMap->insert( "KUrlRequester", SIGNAL(textChanged (const QString& )));
+ s_changedMap->insert( "KIntNumInput", SIGNAL(valueChanged (int)));
+ s_changedMap->insert( "KIntSpinBox", SIGNAL(valueChanged (int)));
+ s_changedMap->insert( "KDoubleNumInput", SIGNAL(valueChanged (double)));
}
+}
+
+QMap<QByteArray, QByteArray> *KConfigDialogManager::propertyMap()
+{
+ initMaps();
+ return s_propertyMap;
+}
+QMap<QString, QByteArray> *KConfigDialogManager::changedMap()
+{
+ initMaps();
+ return s_changedMap;
+}
+
+void KConfigDialogManager::init(bool trackChanges)
+{
+ initMaps();
+ d->trackChanges = trackChanges;
+
// Go through all of the children of the widgets and find all known widgets
(void) parseChildren(m_dialog, trackChanges);
}
@@ -187,37 +258,38 @@
setupWidget(childWidget, item);
- QMap<QString, QByteArray>::const_iterator changedIt = \
changedMap.find(childWidget->className()); + if ( d->trackChanges ) {
+ QMap<QString, QByteArray>::const_iterator changedIt = \
s_changedMap->find(childWidget->className());
- if (changedIt == changedMap.end())
- {
+ if (changedIt == s_changedMap->end())
+ {
// If the class name of the widget wasn't in the monitored widgets map, then \
look for
// it again using the super class name. This fixes a problem with using \
QtRuby/Korundum
// widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, \
even // though it was a 'QWidget'.
- changedIt = changedMap.find(childWidget->metaObject()->superClassName());
- }
+ changedIt = \
s_changedMap->find(childWidget->metaObject()->superClassName()); + }
- if (changedIt == changedMap.end())
- {
- kdWarning(178) << "Don't know how to monitor widget '" << \
childWidget->className() << "' for changes!" << endl;
- }
- else
- {
- connect(childWidget, *changedIt,
+ if (changedIt == s_changedMap->end())
+ {
+ kdWarning(178) << "Don't know how to monitor widget '" << \
childWidget->className() << "' for changes!" << endl; + }
+ else
+ {
+ connect(childWidget, *changedIt,
this, SIGNAL(widgetModified()));
- Q3GroupBox *gb = dynamic_cast<Q3GroupBox *>(childWidget);
- if (!gb)
- bParseChildren = false;
- else
- d->insideGroupBox = true;
-
- QComboBox *cb = dynamic_cast<QComboBox *>(childWidget);
- if (cb && cb->editable())
- connect(cb, SIGNAL(textChanged(const QString &)),
+ QComboBox *cb = dynamic_cast<QComboBox *>(childWidget);
+ if (cb && cb->editable())
+ connect(cb, SIGNAL(textChanged(const QString &)),
this, SIGNAL(widgetModified()));
+ }
}
+ Q3GroupBox *gb = dynamic_cast<Q3GroupBox *>(childWidget);
+ if (!gb)
+ bParseChildren = false;
+ else
+ d->insideGroupBox = true;
}
else
{
@@ -239,10 +311,10 @@
}
}
#ifndef NDEBUG
- else if (widgetName)
+ else if (widgetName && d->trackChanges)
{
- QMap<QString, QByteArray>::const_iterator changedIt = \
changedMap.find(childWidget->className());
- if (changedIt != changedMap.end())
+ QMap<QString, QByteArray>::const_iterator changedIt = \
s_changedMap->find(childWidget->className()); + if (changedIt != \
s_changedMap->end()) {
if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) &&
!qobject_cast<QGroupBox*>(childWidget))
@@ -358,7 +430,14 @@
return;
}
- propertyMap->setProperty(w, v);
+ const QMetaObject* mo = w->metaObject();
+ while (mo && !s_propertyMap->contains(mo->className()))
+ mo = mo->superClass();
+ if (!mo) {
+ kdWarning(178) << w->metaObject()->className() << " widget not handled!" << \
endl; + return;
+ }
+ w->setProperty(s_propertyMap->value(mo->className()), v);
}
QVariant KConfigDialogManager::property(QWidget *w)
@@ -371,7 +450,15 @@
if (cb && cb->editable())
return QVariant(cb->currentText());
- return propertyMap->property(w);
+ const QMetaObject* mo = w->metaObject();
+ while (mo && !s_propertyMap->contains(mo->className()))
+ mo = mo->superClass();
+
+ if (!mo) {
+ kdWarning(178) << w->metaObject()->className() << " widget not handled!" << \
endl; + return QVariant();
+ }
+ return w->property(s_propertyMap->value(mo->className()));
}
bool KConfigDialogManager::hasChanged()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic