diff options
author | hjk <[email protected]> | 2019-11-15 18:42:11 +0100 |
---|---|---|
committer | hjk <[email protected]> | 2019-11-18 08:33:26 +0000 |
commit | 3c6c61d1c82d9de71c2c191e8ee8d28e3ac021ab (patch) | |
tree | 749da47c5183c5e818e79e1cd3d13af8ad8a69c4 /src/plugins/classview/classviewutils.cpp | |
parent | 3ecf3d95753bbfa6affe32ef84cf0727bdbca9be (diff) |
ClassView: Dissolve the internal 'Utils' class
It's regularly getting in my way, and it's rather a namespace anyway.
Also, move the functions that are only used once closer to their
place of use.
Change-Id: I97951aae1b69c04f391afbdd1b491a8a9173a977
Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/plugins/classview/classviewutils.cpp')
-rw-r--r-- | src/plugins/classview/classviewutils.cpp | 192 |
1 files changed, 2 insertions, 190 deletions
diff --git a/src/plugins/classview/classviewutils.cpp b/src/plugins/classview/classviewutils.cpp index 7b4e0d5fbc7..cebea9a6f28 100644 --- a/src/plugins/classview/classviewutils.cpp +++ b/src/plugins/classview/classviewutils.cpp @@ -27,69 +27,12 @@ #include "classviewconstants.h" #include "classviewsymbolinformation.h" -// needed for the correct sorting order -#include <cplusplus/Icons.h> - #include <QStandardItem> #include <QDebug> namespace ClassView { -namespace Constants { - -/*! - \class Utils - \brief The Utils class provides some common utilities. -*/ - -//! Default icon sort order -const int IconSortOrder[] = { - Utils::CodeModelIcon::Namespace, - Utils::CodeModelIcon::Enum, - Utils::CodeModelIcon::Class, - Utils::CodeModelIcon::FuncPublic, - Utils::CodeModelIcon::FuncProtected, - Utils::CodeModelIcon::FuncPrivate, - Utils::CodeModelIcon::FuncPublicStatic, - Utils::CodeModelIcon::FuncProtectedStatic, - Utils::CodeModelIcon::FuncPrivateStatic, - Utils::CodeModelIcon::Signal, - Utils::CodeModelIcon::SlotPublic, - Utils::CodeModelIcon::SlotProtected, - Utils::CodeModelIcon::SlotPrivate, - Utils::CodeModelIcon::VarPublic, - Utils::CodeModelIcon::VarProtected, - Utils::CodeModelIcon::VarPrivate, - Utils::CodeModelIcon::VarPublicStatic, - Utils::CodeModelIcon::VarProtectedStatic, - Utils::CodeModelIcon::VarPrivateStatic, - Utils::CodeModelIcon::Enumerator, - Utils::CodeModelIcon::Keyword, - Utils::CodeModelIcon::Macro, - Utils::CodeModelIcon::Unknown -}; - -} // namespace Constants - namespace Internal { -Utils::Utils() = default; - -/*! - Converts internal location container to QVariant compatible. - \a locations specifies a set of symbol locations. - Returns a list of variant locations that can be added to the data of an - item. -*/ - -QList<QVariant> Utils::locationsToRole(const QSet<SymbolLocation> &locations) -{ - QList<QVariant> locationsVar; - foreach (const SymbolLocation &loc, locations) - locationsVar.append(QVariant::fromValue(loc)); - - return locationsVar; -} - /*! Converts QVariant location container to internal. \a locationsVar contains a list of variant locations from the data of an @@ -97,7 +40,7 @@ QList<QVariant> Utils::locationsToRole(const QSet<SymbolLocation> &locations) Returns a set of symbol locations. */ -QSet<SymbolLocation> Utils::roleToLocations(const QList<QVariant> &locationsVar) +QSet<SymbolLocation> roleToLocations(const QList<QVariant> &locationsVar) { QSet<SymbolLocation> locations; foreach (const QVariant &loc, locationsVar) { @@ -108,50 +51,12 @@ QSet<SymbolLocation> Utils::roleToLocations(const QList<QVariant> &locationsVar) return locations; } -/*! - Returns sort order value for the \a icon. -*/ - -int Utils::iconTypeSortOrder(int icon) -{ - static QHash<int, int> sortOrder; - - // initialization - if (sortOrder.isEmpty()) { - for (int i : Constants::IconSortOrder) - sortOrder.insert(i, sortOrder.count()); - } - - // if it is missing - return the same value - if (!sortOrder.contains(icon)) - return icon; - - return sortOrder[icon]; -} - -/*! - Sets symbol information specified by \a information to \a item. - \a information provides the name, type, and icon for the item. - Returns the filled item. -*/ - -QStandardItem *Utils::setSymbolInformationToItem(const SymbolInformation &information, - QStandardItem *item) -{ - Q_ASSERT(item); - - item->setData(information.name(), Constants::SymbolNameRole); - item->setData(information.type(), Constants::SymbolTypeRole); - item->setData(information.iconType(), Constants::IconTypeRole); - - return item; -} /*! Returns symbol information for \a item. */ -SymbolInformation Utils::symbolInformationFromItem(const QStandardItem *item) +SymbolInformation symbolInformationFromItem(const QStandardItem *item) { Q_ASSERT(item); @@ -173,98 +78,5 @@ SymbolInformation Utils::symbolInformationFromItem(const QStandardItem *item) return SymbolInformation(name, type, iconType); } -/*! - Updates \a item to \a target, so that it is sorted and can be fetched. -*/ - -void Utils::fetchItemToTarget(QStandardItem *item, const QStandardItem *target) -{ - if (!item || !target) - return; - - int itemIndex = 0; - int targetIndex = 0; - int itemRows = item->rowCount(); - int targetRows = target->rowCount(); - - while (itemIndex < itemRows && targetIndex < targetRows) { - const QStandardItem *itemChild = item->child(itemIndex); - const QStandardItem *targetChild = target->child(targetIndex); - - const SymbolInformation &itemInf = symbolInformationFromItem(itemChild); - const SymbolInformation &targetInf = symbolInformationFromItem(targetChild); - - if (itemInf < targetInf) { - ++itemIndex; - } else if (itemInf == targetInf) { - ++itemIndex; - ++targetIndex; - } else { - item->insertRow(itemIndex, targetChild->clone()); - ++itemIndex; - ++itemRows; - ++targetIndex; - } - } - - // append - while (targetIndex < targetRows) { - item->appendRow(target->child(targetIndex)->clone()); - ++targetIndex; - } -} - -/*! - Moves \a item to \a target (sorted). -*/ -void Utils::moveItemToTarget(QStandardItem *item, const QStandardItem *target) -{ - if (!item || !target) - return; - - int itemIndex = 0; - int targetIndex = 0; - int itemRows = item->rowCount(); - int targetRows = target->rowCount(); - - while (itemIndex < itemRows && targetIndex < targetRows) { - QStandardItem *itemChild = item->child(itemIndex); - const QStandardItem *targetChild = target->child(targetIndex); - - const SymbolInformation &itemInf = Utils::symbolInformationFromItem(itemChild); - const SymbolInformation &targetInf = Utils::symbolInformationFromItem(targetChild); - - if (itemInf < targetInf) { - item->removeRow(itemIndex); - --itemRows; - } else if (itemInf == targetInf) { - moveItemToTarget(itemChild, targetChild); - ++itemIndex; - ++targetIndex; - } else { - item->insertRow(itemIndex, targetChild->clone()); - moveItemToTarget(item->child(itemIndex), targetChild); - ++itemIndex; - ++itemRows; - ++targetIndex; - } - } - - // append - while (targetIndex < targetRows) { - item->appendRow(target->child(targetIndex)->clone()); - moveItemToTarget(item->child(itemIndex), target->child(targetIndex)); - ++itemIndex; - ++itemRows; - ++targetIndex; - } - - // remove end of item - while (itemIndex < itemRows) { - item->removeRow(itemIndex); - --itemRows; - } -} - } // namespace Internal } // namespace ClassView |