From 7d6669c25b2e1476b3bf920ec4008f64e6640e08 Mon Sep 17 00:00:00 2001 From: Ignat Semenov Date: Thu, 11 Apr 2013 14:29:37 +0400 Subject: [PATCH] even less code duplication --- plasma/applets/folderview/folderview.cpp | 48 +++++++++++------------- plasma/applets/folderview/folderview.h | 2 + 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/plasma/applets/folderview/folderview.cpp b/plasma/applets/folderview/folderview.cpp index 897cd0e4b5..fcb74a7beb 100644 --- a/plasma/applets/folderview/folderview.cpp +++ b/plasma/applets/folderview/folderview.cpp @@ -755,33 +755,11 @@ void FolderView::createConfigurationInterface(KConfigDialog *parent) uiDisplay.numLinesEdit->setValue(m_numTextLines); uiDisplay.colorButton->setColor(textColor()); - for (int i = 0; i < uiDisplay.sortCombo->maxCount(); i++) { - if (m_sortColumn == uiDisplay.sortCombo->itemData(i).value()) { - uiDisplay.sortCombo->setCurrentIndex(i); - break; - } - } - - for (int i = 0; i < uiDisplay.flowCombo->count(); i++) { - if (m_flow == uiDisplay.flowCombo->itemData(i).value()) { - uiDisplay.flowCombo->setCurrentIndex(i); - break; - } - } - - for (int i = 0; i < uiLocation.titleCombo->count(); i++) { - if (m_labelType == uiLocation.titleCombo->itemData(i).value()) { - uiLocation.titleCombo->setCurrentIndex(i); - break; - } - } - - for (int i = 0; i < uiFilter.filterCombo->count(); i++) { - if (m_filterType == uiFilter.filterCombo->itemData(i).value()) { - uiFilter.filterCombo->setCurrentIndex(i); - break; - } - } + setCurrentItem(uiDisplay.sortCombo, m_sortColumn); + setCurrentItem(uiDisplay.directionCombo, m_sortOrder); + setCurrentItem(uiDisplay.flowCombo, m_flow); + setCurrentItem(uiLocation.titleCombo, m_labelType); + setCurrentItem(uiFilter.filterCombo, m_filterType); filterChanged(uiFilter.filterCombo->currentIndex()); @@ -1090,6 +1068,22 @@ void FolderView::addActionGroupToCombo(QActionGroup* group, QComboBox* combo) } } +// We can not use QComboBox::findData() since in qt4, comparing QVariant's containing +// enums (user types) fails even if the enums contained in the QVariant's are equal +template +void FolderView::setCurrentItem(QComboBox* combo, T current) +{ + if (!combo) + return; + + for (int i = 0; i < combo->maxCount(); i++) { + if (current == combo->itemData(i).value()) { + combo->setCurrentIndex(i); + break; + } + } +} + void FolderView::setupIconView() { if (m_iconView) { diff --git a/plasma/applets/folderview/folderview.h b/plasma/applets/folderview/folderview.h index 946ba9b73b..5a880cb5b6 100644 --- a/plasma/applets/folderview/folderview.h +++ b/plasma/applets/folderview/folderview.h @@ -163,6 +163,8 @@ private: void updatePasteAction(); void addActions(AbstractItemView *view); void addActionGroupToCombo(QActionGroup *group, QComboBox *combo); + template + void setCurrentItem(QComboBox *combo, T current); QColor textColor() const; void setupIconView(); void setUrl(const KUrl &url);