From 5c16ce1d36987142bc634b3b342e03513c723bf8 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 17 Jul 2018 22:49:51 +0400 Subject: [PATCH] Sort icons in the DataDisplayDelegate --- apps/opencs/view/world/datadisplaydelegate.cpp | 18 ++++++++++++++++-- apps/opencs/view/world/datadisplaydelegate.hpp | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/world/datadisplaydelegate.cpp b/apps/opencs/view/world/datadisplaydelegate.cpp index 9db16d593..f0c364bc2 100644 --- a/apps/opencs/view/world/datadisplaydelegate.cpp +++ b/apps/opencs/view/world/datadisplaydelegate.cpp @@ -32,7 +32,7 @@ void CSVWorld::DataDisplayDelegate::buildPixmaps () while (it != mIcons.end()) { - mPixmaps.push_back (std::make_pair (it->first, it->second.pixmap (mIconSize) ) ); + mPixmaps.push_back (std::make_pair (it->mValue, it->mIcon.pixmap (mIconSize) ) ); ++it; } } @@ -142,9 +142,23 @@ void CSVWorld::DataDisplayDelegate::settingChanged (const CSMPrefs::Setting *set void CSVWorld::DataDisplayDelegateFactory::add (int enumValue, const QString& enumName, const QString& iconFilename) { - mIcons.push_back (std::make_pair(enumValue, QIcon(iconFilename))); EnumDelegateFactory::add(enumValue, enumName); + Icon icon; + icon.mValue = enumValue; + icon.mName = enumName; + icon.mIcon = QIcon(iconFilename); + + for (auto it=mIcons.begin(); it!=mIcons.end(); ++it) + { + if (it->mName > enumName) + { + mIcons.insert(it, icon); + return; + } + } + + mIcons.push_back(icon); } CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate ( diff --git a/apps/opencs/view/world/datadisplaydelegate.hpp b/apps/opencs/view/world/datadisplaydelegate.hpp index 540216d78..f8e775369 100755 --- a/apps/opencs/view/world/datadisplaydelegate.hpp +++ b/apps/opencs/view/world/datadisplaydelegate.hpp @@ -11,11 +11,18 @@ namespace CSMPrefs namespace CSVWorld { + struct Icon + { + int mValue; + QIcon mIcon; + QString mName; + }; + class DataDisplayDelegate : public EnumDelegate { public: - typedef std::vector < std::pair < int, QIcon > > IconList; + typedef std::vector IconList; typedef std::vector > ValueList; protected: