diff --git a/debugger/CMakeLists.txt b/debugger/CMakeLists.txt --- a/debugger/CMakeLists.txt +++ b/debugger/CMakeLists.txt @@ -17,6 +17,7 @@ variable/variablewidget.cpp variable/variablecollection.cpp variable/variabletooltip.cpp + variable/variablesortmodel.cpp framestack/framestackmodel.cpp framestack/framestackwidget.cpp ) diff --git a/debugger/variable/variablesortmodel.h b/debugger/variable/variablesortmodel.h --- a/debugger/variable/variablesortmodel.h +++ b/debugger/variable/variablesortmodel.h @@ -25,6 +25,7 @@ #include class QModelIndex; +class QCollator; namespace KDevelop { @@ -35,9 +36,12 @@ public: VariableSortProxyModel(QObject *parent = nullptr); + ~VariableSortProxyModel(); protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; +private: + QCollator *m_collator; }; } diff --git a/debugger/variable/variablesortmodel.cpp b/debugger/variable/variablesortmodel.cpp --- a/debugger/variable/variablesortmodel.cpp +++ b/debugger/variable/variablesortmodel.cpp @@ -30,16 +30,21 @@ VariableSortProxyModel::VariableSortProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { + m_collator = new QCollator(); + m_collator->setNumericMode(true); + m_collator->setCaseSensitivity(Qt::CaseInsensitive); +} + +VariableSortProxyModel::~VariableSortProxyModel() +{ + delete m_collator; } bool VariableSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { - QCollator collator; - collator.setNumericMode(true); - collator.setCaseSensitivity(Qt::CaseInsensitive); const QString leftString = sourceModel()->data(left).toString(); const QString rightString = sourceModel()->data(right).toString(); - int result = collator.compare(leftString, rightString); + int result = m_collator->compare(leftString, rightString); return result < 0; } diff --git a/debugger/variable/variablewidget.cpp b/debugger/variable/variablewidget.cpp --- a/debugger/variable/variablewidget.cpp +++ b/debugger/variable/variablewidget.cpp @@ -31,6 +31,7 @@ #include #include "../interfaces/ivariablecontroller.h" #include "variablecollection.h" +#include "variablesortmodel.h" #include "util/debug.h" /** The variables widget is passive, and is invoked by the rest of the @@ -76,7 +77,7 @@ setWindowIcon(QIcon::fromTheme("debugger")); setWindowTitle(i18n("Debugger Variables")); - m_proxy = new QSortFilterProxyModel; + m_proxy = new VariableSortProxyModel; varTree_ = new VariableTree(controller, this, m_proxy); setFocusProxy(varTree_);