kdeui: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-04 05:52:56 +03:00
parent 942e50f279
commit c23e68ad4d
2 changed files with 406 additions and 429 deletions

View file

@ -43,141 +43,146 @@ K_GLOBAL_STATIC(MyHash, s_changedMap)
// see kdebug.areas // see kdebug.areas
static const int s_kconfigdialogmanagerarea = 300; static const int s_kconfigdialogmanagerarea = 300;
class KConfigDialogManager::Private { class KConfigDialogManager::Private
{
public:
Private(KConfigDialogManager *q)
: q(q),
insideGroupBox(false)
{
}
public: public:
Private(KConfigDialogManager *q) : q(q), insideGroupBox(false) { } KConfigDialogManager *q;
public: /**
KConfigDialogManager *q; * KConfigSkeleton object used to store settings
*/
KCoreConfigSkeleton *m_conf;
/** /**
* KConfigSkeleton object used to store settings * Dialog being managed
*/ */
KCoreConfigSkeleton *m_conf; QWidget* m_dialog;
/** QHash<QString, QWidget*> knownWidget;
* Dialog being managed QHash<QString, QWidget*> buddyWidget;
*/ bool insideGroupBox;
QWidget *m_dialog; bool trackChanges;
QHash<QString, QWidget *> knownWidget;
QHash<QString, QWidget *> buddyWidget;
bool insideGroupBox : 1;
bool trackChanges : 1;
}; };
KConfigDialogManager::KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf) KConfigDialogManager::KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf)
: QObject(parent), d(new Private(this)) : QObject(parent),
d(new Private(this))
{ {
d->m_conf = conf; d->m_conf = conf;
d->m_dialog = parent; d->m_dialog = parent;
init(true); init(true);
} }
KConfigDialogManager::KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf) KConfigDialogManager::KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf)
: QObject(parent), d(new Private(this)) : QObject(parent),
d(new Private(this))
{ {
d->m_conf = conf; d->m_conf = conf;
d->m_dialog = parent; d->m_dialog = parent;
init(true); init(true);
} }
KConfigDialogManager::~KConfigDialogManager() KConfigDialogManager::~KConfigDialogManager()
{ {
delete d; delete d;
} }
void KConfigDialogManager::initMaps() void KConfigDialogManager::initMaps()
{ {
if ( s_propertyMap->isEmpty() ) { if (s_propertyMap->isEmpty()) {
s_propertyMap->insert("QCheckBox", "checked"); s_propertyMap->insert("QCheckBox", "checked");
s_propertyMap->insert("QPushButton", "toggled"); s_propertyMap->insert("QPushButton", "toggled");
s_propertyMap->insert("QRadioButton", "checked"); s_propertyMap->insert("QRadioButton", "checked");
s_propertyMap->insert("QGroupBox", "text"); s_propertyMap->insert("QGroupBox", "text");
// s_propertyMap->insert("QComboBox", "currentText"); // s_propertyMap->insert("QComboBox", "currentText");
s_propertyMap->insert("QDateEdit", "date"); s_propertyMap->insert("QDateEdit", "date");
s_propertyMap->insert("QDateTimeEdit", "dateTime"); s_propertyMap->insert("QDateTimeEdit", "dateTime");
s_propertyMap->insert("QDial", "value"); s_propertyMap->insert("QDial", "value");
s_propertyMap->insert("QDoubleSpinBox", "value"); s_propertyMap->insert("QDoubleSpinBox", "value");
s_propertyMap->insert("QLineEdit", "text"); s_propertyMap->insert("QLineEdit", "text");
s_propertyMap->insert("QSlider", "value"); s_propertyMap->insert("QSlider", "value");
s_propertyMap->insert("QSpinBox", "value"); s_propertyMap->insert("QSpinBox", "value");
s_propertyMap->insert("QTextEdit", "html"); s_propertyMap->insert("QTextEdit", "html");
s_propertyMap->insert("QTextBrowser", "html"); s_propertyMap->insert("QTextBrowser", "html");
s_propertyMap->insert("QPlainTextEdit", "plainText"); s_propertyMap->insert("QPlainTextEdit", "plainText");
// s_propertyMap->insert( "QTabWidget", ""); // s_propertyMap->insert( "QTabWidget", "");
// s_propertyMap->insert("KComboBox", "currentText"); // s_propertyMap->insert("KComboBox", "currentText");
s_propertyMap->insert("KFontRequester", "font"); s_propertyMap->insert("KFontRequester", "font");
s_propertyMap->insert("KHistoryCombo", "historyItems"); s_propertyMap->insert("KHistoryCombo", "historyItems");
s_propertyMap->insert("KColorCombo", "color"); s_propertyMap->insert("KColorCombo", "color");
s_propertyMap->insert("KColorButton", "color"); s_propertyMap->insert("KColorButton", "color");
s_propertyMap->insert("KCalendarWidget", "selectedDate"); s_propertyMap->insert("KCalendarWidget", "selectedDate");
s_propertyMap->insert("KTimeEdit", "time"); s_propertyMap->insert("KTimeEdit", "time");
s_propertyMap->insert("KEditListWidget", "items"); s_propertyMap->insert("KEditListWidget", "items");
// s_propertyMap->insert("KListWidget", ""); // s_propertyMap->insert("KListWidget", "");
s_propertyMap->insert("KLineEdit", "text"); s_propertyMap->insert("KLineEdit", "text");
s_propertyMap->insert("KRestrictedLine", "text"); s_propertyMap->insert("KRestrictedLine", "text");
s_propertyMap->insert("KTextEdit", "html"); s_propertyMap->insert("KTextEdit", "html");
s_propertyMap->insert("KUrlRequester", "text"); s_propertyMap->insert("KUrlRequester", "text");
s_propertyMap->insert("KUrlComboRequester", "text"); s_propertyMap->insert("KUrlComboRequester", "text");
s_propertyMap->insert("KUrlComboBox", "urls"); s_propertyMap->insert("KUrlComboBox", "urls");
s_propertyMap->insert("KIntNumInput", "value"); s_propertyMap->insert("KIntNumInput", "value");
s_propertyMap->insert("KDoubleNumInput", "value"); s_propertyMap->insert("KDoubleNumInput", "value");
s_propertyMap->insert("KButtonGroup", "current"); s_propertyMap->insert("KButtonGroup", "current");
} }
if( s_changedMap->isEmpty() ) if (s_changedMap->isEmpty()) {
{ // Katie
// Katie s_changedMap->insert("QCheckBox", SIGNAL(stateChanged(int)));
s_changedMap->insert("QCheckBox", SIGNAL(stateChanged(int))); s_changedMap->insert("QPushButton", SIGNAL(clicked(bool)));
s_changedMap->insert("QPushButton", SIGNAL(clicked(bool))); s_changedMap->insert("QRadioButton", SIGNAL(toggled(bool)));
s_changedMap->insert("QRadioButton", SIGNAL(toggled(bool))); // can only store one thing so can't have a ButtonGroup that is checkable
// can only store one thing so can't have a ButtonGroup that is checkable // s_changedMap->insert("QButtonGroup", SIGNAL(buttonClicked(int)));
// s_changedMap->insert("QButtonGroup", SIGNAL(buttonClicked(int))); s_changedMap->insert("QGroupBox", SIGNAL(toggled(bool)));
s_changedMap->insert("QGroupBox", SIGNAL(toggled(bool))); s_changedMap->insert("QComboBox", SIGNAL(activated(int)));
s_changedMap->insert("QComboBox", SIGNAL(activated(int))); // s_changedMap->insert("QComboBox", SIGNAL(textChanged(QString)));
// s_changedMap->insert("QComboBox", SIGNAL(textChanged(QString))); s_changedMap->insert("QDateEdit", SIGNAL(dateChanged(QDate)));
s_changedMap->insert("QDateEdit", SIGNAL(dateChanged(QDate))); s_changedMap->insert("QDateTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(timeChanged(QTime))); s_changedMap->insert("QDateTimeEdit", SIGNAL(dateTimeChanged(QDateTime)));
s_changedMap->insert("QDateTimeEdit", SIGNAL(dateTimeChanged(QDateTime))); s_changedMap->insert("QDial", SIGNAL(valueChanged(int)));
s_changedMap->insert("QDial", SIGNAL(valueChanged(int))); s_changedMap->insert("QDoubleSpinBox", SIGNAL(valueChanged(double)));
s_changedMap->insert("QDoubleSpinBox", SIGNAL(valueChanged(double))); s_changedMap->insert("QLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("QLineEdit", SIGNAL(textChanged(QString))); s_changedMap->insert("QSlider", SIGNAL(valueChanged(int)));
s_changedMap->insert("QSlider", SIGNAL(valueChanged(int))); s_changedMap->insert("QSpinBox", SIGNAL(valueChanged(int)));
s_changedMap->insert("QSpinBox", SIGNAL(valueChanged(int))); s_changedMap->insert("QTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QTextEdit", SIGNAL(textChanged())); s_changedMap->insert("QTextBrowser", SIGNAL(sourceChanged(QString)));
s_changedMap->insert("QTextBrowser", SIGNAL(sourceChanged(QString))); s_changedMap->insert("QPlainTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("QPlainTextEdit", SIGNAL(textChanged())); s_changedMap->insert("QTabWidget", SIGNAL(currentChanged(int)));
s_changedMap->insert("QTabWidget", SIGNAL(currentChanged(int)));
// KDE // KDE
s_changedMap->insert("KComboBox", SIGNAL(activated(int))); s_changedMap->insert("KComboBox", SIGNAL(activated(int)));
s_changedMap->insert("KFontRequester", SIGNAL(fontSelected(QFont))); s_changedMap->insert("KFontRequester", SIGNAL(fontSelected(QFont)));
s_changedMap->insert("KHistoryCombo", SIGNAL(activated(int))); s_changedMap->insert("KHistoryCombo", SIGNAL(activated(int)));
s_changedMap->insert("KColorCombo", SIGNAL(activated(QColor))); s_changedMap->insert("KColorCombo", SIGNAL(activated(QColor)));
s_changedMap->insert("KColorButton", SIGNAL(changed(QColor))); s_changedMap->insert("KColorButton", SIGNAL(changed(QColor)));
s_changedMap->insert("KCalendarWidget", SIGNAL(activated(QDate))); s_changedMap->insert("KCalendarWidget", SIGNAL(activated(QDate)));
s_changedMap->insert("KTimeEdit", SIGNAL(timeChanged(QTime))); s_changedMap->insert("KTimeEdit", SIGNAL(timeChanged(QTime)));
s_changedMap->insert("KEditListWidget", SIGNAL(changed())); s_changedMap->insert("KEditListWidget", SIGNAL(changed()));
s_changedMap->insert("KListWidget", SIGNAL(itemSelectionChanged())); s_changedMap->insert("KListWidget", SIGNAL(itemSelectionChanged()));
s_changedMap->insert("KLineEdit", SIGNAL(textChanged(QString))); s_changedMap->insert("KLineEdit", SIGNAL(textChanged(QString)));
s_changedMap->insert("KRestrictedLine", SIGNAL(textChanged(QString))); s_changedMap->insert("KRestrictedLine", SIGNAL(textChanged(QString)));
s_changedMap->insert("KTextEdit", SIGNAL(textChanged())); s_changedMap->insert("KTextEdit", SIGNAL(textChanged()));
s_changedMap->insert("KUrlRequester", SIGNAL(textChanged(QString))); s_changedMap->insert("KUrlRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboRequester", SIGNAL(textChanged(QString))); s_changedMap->insert("KUrlComboRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert("KUrlComboBox", SIGNAL(urlActivated(KUrl))); s_changedMap->insert("KUrlComboBox", SIGNAL(urlActivated(KUrl)));
s_changedMap->insert("KIntNumInput", SIGNAL(valueChanged(int))); s_changedMap->insert("KIntNumInput", SIGNAL(valueChanged(int)));
s_changedMap->insert("KDoubleNumInput", SIGNAL(valueChanged(double))); s_changedMap->insert("KDoubleNumInput", SIGNAL(valueChanged(double)));
s_changedMap->insert("KButtonGroup", SIGNAL(changed(int))); s_changedMap->insert("KButtonGroup", SIGNAL(changed(int)));
} }
} }
QHash<QString, QByteArray> *KConfigDialogManager::propertyMap() QHash<QString, QByteArray> *KConfigDialogManager::propertyMap()
{ {
initMaps(); initMaps();
return s_propertyMap; return s_propertyMap;
} }
QHash<QString, QByteArray> *KConfigDialogManager::changedMap() QHash<QString, QByteArray> *KConfigDialogManager::changedMap()
@ -188,212 +193,201 @@ QHash<QString, QByteArray> *KConfigDialogManager::changedMap()
void KConfigDialogManager::init(bool trackChanges) void KConfigDialogManager::init(bool trackChanges)
{ {
initMaps(); initMaps();
d->trackChanges = trackChanges; d->trackChanges = trackChanges;
// Go through all of the children of the widgets and find all known widgets // Go through all of the children of the widgets and find all known widgets
(void) parseChildren(d->m_dialog, trackChanges); (void) parseChildren(d->m_dialog, trackChanges);
} }
void KConfigDialogManager::addWidget(QWidget *widget) void KConfigDialogManager::addWidget(QWidget *widget)
{ {
(void) parseChildren(widget, true); (void) parseChildren(widget, true);
} }
void KConfigDialogManager::setupWidget(QWidget *widget, KConfigSkeletonItem *item) void KConfigDialogManager::setupWidget(QWidget *widget, KConfigSkeletonItem *item)
{ {
QVariant minValue = item->minValue(); QVariant minValue = item->minValue();
if (minValue.isValid()) if (minValue.isValid()) {
{ // Only q3datetimeedit is using this property we can remove it if we stop supporting Qt3Support
// Only q3datetimeedit is using this property we can remove it if we stop supporting Qt3Support if (widget->metaObject()->indexOfProperty("minValue") != -1) {
if (widget->metaObject()->indexOfProperty("minValue") != -1) widget->setProperty("minValue", minValue);
widget->setProperty("minValue", minValue); }
if (widget->metaObject()->indexOfProperty("minimum") != -1) if (widget->metaObject()->indexOfProperty("minimum") != -1) {
widget->setProperty("minimum", minValue); widget->setProperty("minimum", minValue);
} }
QVariant maxValue = item->maxValue();
if (maxValue.isValid())
{
// Only q3datetimeedit is using that property we can remove it if we stop supporting Qt3Support
if (widget->metaObject()->indexOfProperty("maxValue") != -1)
widget->setProperty("maxValue", maxValue);
if (widget->metaObject()->indexOfProperty("maximum") != -1)
widget->setProperty("maximum", maxValue);
}
if (widget->whatsThis().isEmpty())
{
QString whatsThis = item->whatsThis();
if ( !whatsThis.isEmpty() )
{
widget->setWhatsThis(whatsThis );
} }
} QVariant maxValue = item->maxValue();
if (maxValue.isValid()) {
if (widget->toolTip().isEmpty()) // Only q3datetimeedit is using that property we can remove it if we stop supporting Qt3Support
{ if (widget->metaObject()->indexOfProperty("maxValue") != -1) {
QString toolTip = item->toolTip(); widget->setProperty("maxValue", maxValue);
if ( !toolTip.isEmpty() ) }
{ if (widget->metaObject()->indexOfProperty("maximum") != -1) {
widget->setToolTip(toolTip); widget->setProperty("maximum", maxValue);
}
} }
}
if(!item->isEqual( property(widget) )) if (widget->whatsThis().isEmpty()) {
setProperty( widget, item->property() ); QString whatsThis = item->whatsThis();
if (!whatsThis.isEmpty()) {
widget->setWhatsThis(whatsThis);
}
}
if (widget->toolTip().isEmpty()) {
QString toolTip = item->toolTip();
if (!toolTip.isEmpty()) {
widget->setToolTip(toolTip);
}
}
if (!item->isEqual(property(widget))) {
setProperty(widget, item->property());
}
} }
bool KConfigDialogManager::parseChildren(const QWidget *widget, bool trackChanges) bool KConfigDialogManager::parseChildren(const QWidget *widget, bool trackChanges)
{ {
bool valueChanged = false; bool valueChanged = false;
const QList<QObject*> listOfChildren = widget->children(); const QList<QObject*> listOfChildren = widget->children();
if(listOfChildren.count()==0) //?? XXX if (listOfChildren.count() == 0) {
return valueChanged; return valueChanged;
}
foreach ( QObject *object, listOfChildren ) foreach (QObject *object, listOfChildren) {
{ if(!object->isWidgetType()) {
if(!object->isWidgetType()) // Skip non-widgets
continue; // Skip non-widgets continue;
}
QWidget *childWidget = static_cast<QWidget *>(object);
QWidget *childWidget = static_cast<QWidget *>(object);
QString widgetName = childWidget->objectName();
bool bParseChildren = true; QString widgetName = childWidget->objectName();
bool bSaveInsideGroupBox = d->insideGroupBox; bool bParseChildren = true;
bool bSaveInsideGroupBox = d->insideGroupBox;
if (widgetName.startsWith(QLatin1String("kcfg_")))
{ if (widgetName.startsWith(QLatin1String("kcfg_"))) {
// This is one of our widgets! // This is one of our widgets!
QString configId = widgetName.mid(5); QString configId = widgetName.mid(5);
KConfigSkeletonItem *item = d->m_conf->findItem(configId); KConfigSkeletonItem *item = d->m_conf->findItem(configId);
if (item) if (item) {
{ d->knownWidget.insert(configId, childWidget);
d->knownWidget.insert(configId, childWidget);
setupWidget(childWidget, item);
setupWidget(childWidget, item);
if (d->trackChanges) {
if ( d->trackChanges ) { QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
if (changedIt == s_changedMap->constEnd()) {
if (changedIt == s_changedMap->constEnd()) // 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
// If the class name of the widget wasn't in the monitored widgets map, then look for // widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, even
// it again using the super class name. This fixes a problem with using QtRuby/Korundum // though it was a 'QWidget'.
// widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, even if ( childWidget->metaObject()->superClass()) {
// though it was a 'QWidget'. changedIt = s_changedMap->constFind(childWidget->metaObject()->superClass()->className());
if ( childWidget->metaObject()->superClass() ) } else {
changedIt = s_changedMap->constFind(childWidget->metaObject()->superClass()->className()); changedIt = s_changedMap->constFind(QString());
else }
changedIt = s_changedMap->constFind(QString()); }
}
if (changedIt == s_changedMap->constEnd()) {
if (changedIt == s_changedMap->constEnd()) kWarning(s_kconfigdialogmanagerarea) << "Don't know how to monitor widget '" << childWidget->metaObject()->className() << "' for changes!";
{ } else {
kWarning(s_kconfigdialogmanagerarea) << "Don't know how to monitor widget '" << childWidget->metaObject()->className() << "' for changes!"; connect(childWidget, *changedIt, this, SIGNAL(widgetModified()));
}
else QComboBox *cb = qobject_cast<QComboBox *>(childWidget);
{ if (cb && cb->isEditable())
connect(childWidget, *changedIt, connect(cb, SIGNAL(editTextChanged(QString)), this, SIGNAL(widgetModified()));
this, SIGNAL(widgetModified())); }
}
QComboBox *cb = qobject_cast<QComboBox *>(childWidget); QGroupBox *gb = qobject_cast<QGroupBox *>(childWidget);
if (cb && cb->isEditable()) if (!gb) {
connect(cb, SIGNAL(editTextChanged(QString)), bParseChildren = false;
this, SIGNAL(widgetModified())); } else {
} d->insideGroupBox = true;
}
} else {
kWarning(s_kconfigdialogmanagerarea) << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'";
}
} else if (QLabel *label = qobject_cast<QLabel*>(childWidget)) {
QWidget *buddy = label->buddy();
if (!buddy) {
continue;
}
QString buddyName = buddy->objectName();
if (buddyName.startsWith(QLatin1String("kcfg_"))) {
// This is one of our widgets!
QString configId = buddyName.mid(5);
d->buddyWidget.insert(configId, childWidget);
}
} }
QGroupBox *gb = qobject_cast<QGroupBox *>(childWidget);
if (!gb)
bParseChildren = false;
else
d->insideGroupBox = true;
}
else
{
kWarning(s_kconfigdialogmanagerarea) << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'";
}
}
else if (QLabel *label = qobject_cast<QLabel*>(childWidget))
{
QWidget *buddy = label->buddy();
if (!buddy)
continue;
QString buddyName = buddy->objectName();
if (buddyName.startsWith(QLatin1String("kcfg_")))
{
// This is one of our widgets!
QString configId = buddyName.mid(5);
d->buddyWidget.insert(configId, childWidget);
}
}
#ifndef NDEBUG #ifndef NDEBUG
else if (!widgetName.isEmpty() && d->trackChanges) else if (!widgetName.isEmpty() && d->trackChanges) {
{ QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className());
QHash<QString, QByteArray>::const_iterator changedIt = s_changedMap->constFind(childWidget->metaObject()->className()); if (changedIt != s_changedMap->constEnd()) {
if (changedIt != s_changedMap->constEnd()) if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) &&
{ !qobject_cast<QGroupBox*>(childWidget) &&!qobject_cast<QTabWidget*>(childWidget)) {
if ((!d->insideGroupBox || !qobject_cast<QRadioButton*>(childWidget)) && kDebug(s_kconfigdialogmanagerarea) << "Widget '" << widgetName << "' (" << childWidget->metaObject()->className() << ") remains unmanaged.";
!qobject_cast<QGroupBox*>(childWidget) &&!qobject_cast<QTabWidget*>(childWidget) ) }
kDebug(s_kconfigdialogmanagerarea) << "Widget '" << widgetName << "' (" << childWidget->metaObject()->className() << ") remains unmanaged."; }
} }
} }
#endif #endif
if(bParseChildren) if (bParseChildren) {
{ // this widget is not known as something we can store.
// this widget is not known as something we can store. // Maybe we can store one of its children.
// Maybe we can store one of its children. valueChanged |= parseChildren(childWidget, trackChanges);
valueChanged |= parseChildren(childWidget, trackChanges); }
d->insideGroupBox = bSaveInsideGroupBox;
} }
d->insideGroupBox = bSaveInsideGroupBox; return valueChanged;
}
return valueChanged;
} }
void KConfigDialogManager::updateWidgets() void KConfigDialogManager::updateWidgets()
{ {
bool changed = false; bool changed = false;
bool bSignalsBlocked = signalsBlocked(); bool bSignalsBlocked = signalsBlocked();
blockSignals(true); blockSignals(true);
QWidget *widget; QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget ); QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) { while(it.hasNext()) {
it.next(); it.next();
widget = it.value(); widget = it.value();
KConfigSkeletonItem *item = d->m_conf->findItem(it.key()); KConfigSkeletonItem* item = d->m_conf->findItem(it.key());
if (!item) if (!item) {
{ kWarning(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' has disappeared!";
kWarning(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' has disappeared!"; continue;
continue; }
}
if(!item->isEqual( property(widget) )) if (!item->isEqual(property(widget))) {
{ setProperty(widget, item->property());
setProperty( widget, item->property() ); // kDebug(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' [" << widget->className() << "] has changed";
// kDebug(s_kconfigdialogmanagerarea) << "The setting '" << it.key() << "' [" << widget->className() << "] has changed"; changed = true;
changed = true; }
} if (item->isImmutable()) {
if (item->isImmutable()) widget->setEnabled(false);
{ QWidget *buddy = d->buddyWidget.value(it.key(), 0);
widget->setEnabled(false); if (buddy) {
QWidget *buddy = d->buddyWidget.value(it.key(), 0); buddy->setEnabled(false);
if (buddy) }
buddy->setEnabled(false); }
} }
} blockSignals(bSignalsBlocked);
blockSignals(bSignalsBlocked);
if (changed) if (changed) {
QTimer::singleShot(0, this, SIGNAL(widgetModified())); QTimer::singleShot(0, this, SIGNAL(widgetModified()));
}
} }
void KConfigDialogManager::updateWidgetsDefault() void KConfigDialogManager::updateWidgetsDefault()
{ {
bool bUseDefaults = d->m_conf->useDefaults(true); bool bUseDefaults = d->m_conf->useDefaults(true);
updateWidgets(); updateWidgets();
d->m_conf->useDefaults(bUseDefaults); d->m_conf->useDefaults(bUseDefaults);
} }
void KConfigDialogManager::updateSettings() void KConfigDialogManager::updateSettings()
@ -401,7 +395,7 @@ void KConfigDialogManager::updateSettings()
bool changed = false; bool changed = false;
QWidget *widget; QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget ); QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) { while(it.hasNext()) {
it.next(); it.next();
widget = it.value(); widget = it.value();
@ -413,13 +407,12 @@ void KConfigDialogManager::updateSettings()
} }
QVariant fromWidget = property(widget); QVariant fromWidget = property(widget);
if(!item->isEqual( fromWidget )) { if(!item->isEqual(fromWidget)) {
item->setProperty( fromWidget ); item->setProperty( fromWidget );
changed = true; changed = true;
} }
} }
if (changed) if (changed) {
{
d->m_conf->writeConfig(); d->m_conf->writeConfig();
emit settingsChanged(); emit settingsChanged();
} }
@ -441,15 +434,6 @@ QByteArray KConfigDialogManager::getCustomProperty(const QWidget *widget) const
void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v) void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
{ {
/* QButtonGroup *bg = qobject_cast<QButtonGroup *>(w);
if (bg)
{
QAbstractButton *b = bg->button(v.toInt());
if (b)
b->setDown(true);
return;
}*/
QByteArray customproperty = getCustomProperty(w); QByteArray customproperty = getCustomProperty(w);
if (customproperty.isEmpty()) { if (customproperty.isEmpty()) {
customproperty = s_propertyMap->value(w->metaObject()->className()); customproperty = s_propertyMap->value(w->metaObject()->className());
@ -480,10 +464,6 @@ void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
QVariant KConfigDialogManager::property(QWidget *w) const QVariant KConfigDialogManager::property(QWidget *w) const
{ {
/* QButtonGroup *bg = qobject_cast<QButtonGroup *>(w);
if (bg && bg->checkedButton())
return QVariant(bg->id(bg->checkedButton()));*/
QByteArray customproperty = getCustomProperty(w); QByteArray customproperty = getCustomProperty(w);
if (customproperty.isEmpty()) { if (customproperty.isEmpty()) {
customproperty = s_propertyMap->value(w->metaObject()->className()); customproperty = s_propertyMap->value(w->metaObject()->className());
@ -509,7 +489,7 @@ QVariant KConfigDialogManager::property(QWidget *w) const
bool KConfigDialogManager::hasChanged() const bool KConfigDialogManager::hasChanged() const
{ {
QWidget *widget; QWidget *widget;
QHashIterator<QString, QWidget *> it( d->knownWidget) ; QHashIterator<QString, QWidget*> it(d->knownWidget);
while(it.hasNext()) { while(it.hasNext()) {
it.next(); it.next();
widget = it.value(); widget = it.value();
@ -520,7 +500,7 @@ bool KConfigDialogManager::hasChanged() const
continue; continue;
} }
if(!item->isEqual( property(widget) )) { if(!item->isEqual( property(widget))) {
// kDebug(s_kconfigdialogmanagerarea) << "Widget for '" << it.key() << "' has changed."; // kDebug(s_kconfigdialogmanagerarea) << "Widget for '" << it.key() << "' has changed.";
return true; return true;
} }
@ -530,10 +510,10 @@ bool KConfigDialogManager::hasChanged() const
bool KConfigDialogManager::isDefault() const bool KConfigDialogManager::isDefault() const
{ {
bool bUseDefaults = d->m_conf->useDefaults(true); bool bUseDefaults = d->m_conf->useDefaults(true);
bool result = !hasChanged(); bool result = !hasChanged();
d->m_conf->useDefaults(bUseDefaults); d->m_conf->useDefaults(bUseDefaults);
return result; return result;
} }
#include "moc_kconfigdialogmanager.cpp" #include "moc_kconfigdialogmanager.cpp"

View file

@ -82,132 +82,129 @@ class KConfigSkeletonItem;
* @author Benjamin C Meyer <ben+kdelibs at meyerhome dot net> * @author Benjamin C Meyer <ben+kdelibs at meyerhome dot net>
* @author Waldo Bastian <bastian@kde.org> * @author Waldo Bastian <bastian@kde.org>
*/ */
class KDEUI_EXPORT KConfigDialogManager : public QObject { class KDEUI_EXPORT KConfigDialogManager : public QObject
{
Q_OBJECT Q_OBJECT
Q_SIGNALS: Q_SIGNALS:
/** /**
* One or more of the settings have been saved (such as when the user * One or more of the settings have been saved (such as when the user
* clicks on the Apply button). This is only emitted by updateSettings() * clicks on the Apply button). This is only emitted by updateSettings()
* whenever one or more setting were changed and consequently saved. * whenever one or more setting were changed and consequently saved.
*/ */
void settingsChanged(); void settingsChanged();
/** /**
* TODO: Verify * TODO: Verify
* One or more of the settings have been changed. * One or more of the settings have been changed.
* @param widget - The widget group (pass in via addWidget()) that * @param widget - The widget group (pass in via addWidget()) that
* contains the one or more modified setting. * contains the one or more modified setting.
* @see settingsChanged() * @see settingsChanged()
*/ */
void settingsChanged( QWidget *widget ); void settingsChanged(QWidget *widget);
/**
* If retrieveSettings() was told to track changes then if
* any known setting was changed this signal will be emitted. Note
* that a settings can be modified several times and might go back to the
* original saved state. hasChanged() will tell you if anything has
* actually changed from the saved values.
*/
void widgetModified();
/**
* If retrieveSettings() was told to track changes then if
* any known setting was changed this signal will be emitted. Note
* that a settings can be modified several times and might go back to the
* original saved state. hasChanged() will tell you if anything has
* actually changed from the saved values.
*/
void widgetModified();
public: public:
/**
* Constructor.
* @param parent Dialog widget to manage
* @param conf Object that contains settings
*/
KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf);
/** /**
* Constructor. * Constructor.
* @param parent Dialog widget to manage * @param parent Dialog widget to manage
* @param conf Object that contains settings * @param conf Object that contains settings
*/ */
KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf); KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf);
/** /**
* Constructor. * Destructor.
* @param parent Dialog widget to manage */
* @param conf Object that contains settings ~KConfigDialogManager();
*/
KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf);
/** /**
* Destructor. * Add additional widgets to manage
*/ * @param widget Additional widget to manage, inlcuding all its children
~KConfigDialogManager(); */
void addWidget(QWidget *widget);
/** /**
* Add additional widgets to manage * Returns whether the current state of the known widgets are
* @param widget Additional widget to manage, inlcuding all its children * different from the state in the config object.
*/ */
void addWidget(QWidget *widget); bool hasChanged() const;
/** /**
* Returns whether the current state of the known widgets are * Returns whether the current state of the known widgets are
* different from the state in the config object. * the same as the default state in the config object.
*/ */
bool hasChanged() const; bool isDefault() const;
/** /**
* Returns whether the current state of the known widgets are * Retrieve the property map
* the same as the default state in the config object. */
*/ static QHash<QString, QByteArray>* propertyMap();
bool isDefault() const;
/**
* Retrieve the property map
*/
static QHash<QString, QByteArray> *propertyMap();
/** /**
* Retrieve the widget change map * Retrieve the widget change map
*/ */
static QHash<QString, QByteArray> *changedMap(); static QHash<QString, QByteArray>* changedMap();
public Q_SLOTS: public Q_SLOTS:
/** /**
* Traverse the specified widgets, saving the settings of all known * Traverse the specified widgets, saving the settings of all known
* widgets in the settings object. * widgets in the settings object.
* *
* Example use: User clicks Ok or Apply button in a configure dialog. * Example use: User clicks Ok or Apply button in a configure dialog.
*/ */
void updateSettings(); void updateSettings();
/** /**
* Traverse the specified widgets, sets the state of all known * Traverse the specified widgets, sets the state of all known
* widgets according to the state in the settings object. * widgets according to the state in the settings object.
* *
* Example use: Initialisation of dialog. * Example use: Initialisation of dialog.
* Example use: User clicks Reset button in a configure dialog. * Example use: User clicks Reset button in a configure dialog.
*/ */
void updateWidgets(); void updateWidgets();
/** /**
* Traverse the specified widgets, sets the state of all known * Traverse the specified widgets, sets the state of all known
* widgets according to the default state in the settings object. * widgets according to the default state in the settings object.
* *
* Example use: User clicks Defaults button in a configure dialog. * Example use: User clicks Defaults button in a configure dialog.
*/ */
void updateWidgetsDefault(); void updateWidgetsDefault();
protected: protected:
/**
* @param trackChanges - If any changes by the widgets should be tracked
* set true. This causes the emitting the modified() signal when
* something changes.
* TODO: @return bool - True if any setting was changed from the default.
*/
void init(bool trackChanges);
/** /**
* @param trackChanges - If any changes by the widgets should be tracked * Recursive function that finds all known children.
* set true. This causes the emitting the modified() signal when * Goes through the children of widget and if any are known and not being
* something changes. * ignored, stores them in currentGroup. Also checks if the widget
* TODO: @return bool - True if any setting was changed from the default. * should be disabled because it is set immutable.
*/ * @param widget - Parent of the children to look at.
void init(bool trackChanges); * @param trackChanges - If true then tracks any changes to the children of
* widget that are known.
/** * @return bool - If a widget was set to something other than its default.
* Recursive function that finds all known children. */
* Goes through the children of widget and if any are known and not being
* ignored, stores them in currentGroup. Also checks if the widget
* should be disabled because it is set immutable.
* @param widget - Parent of the children to look at.
* @param trackChanges - If true then tracks any changes to the children of
* widget that are known.
* @return bool - If a widget was set to something other than its default.
*/
bool parseChildren(const QWidget *widget, bool trackChanges); bool parseChildren(const QWidget *widget, bool trackChanges);
/** /**
@ -217,36 +214,36 @@ protected:
*/ */
QByteArray getCustomProperty(const QWidget *widget) const; QByteArray getCustomProperty(const QWidget *widget) const;
/** /**
* Set a property * Set a property
*/ */
void setProperty(QWidget *w, const QVariant &v); void setProperty(QWidget *w, const QVariant &v);
/** /**
* Retrieve a property * Retrieve a property
*/ */
QVariant property(QWidget *w) const; QVariant property(QWidget *w) const;
/** /**
* Setup secondary widget properties * Setup secondary widget properties
*/ */
void setupWidget(QWidget *widget, KConfigSkeletonItem *item); void setupWidget(QWidget *widget, KConfigSkeletonItem *item);
/** /**
* Initializes the property maps * Initializes the property maps
*/ */
static void initMaps(); static void initMaps();
private: private:
class Private; class Private;
friend class Private; friend class Private;
/** /**
* KConfigDialogManager Private class. * KConfigDialogManager Private class.
*/ */
Private *const d; Private *const d;
Q_DISABLE_COPY(KConfigDialogManager) Q_DISABLE_COPY(KConfigDialogManager)
}; };
#endif // KCONFIGDIALOGMANAGER_H #endif // KCONFIGDIALOGMANAGER_H