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 new file mode 100644 --- /dev/null +++ b/debugger/variable/variablesortmodel.h @@ -0,0 +1,43 @@ +/* + * KDevelop Debugger Support + * + * Copyright 2016 Mikhail Ivchenko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_VARIABLESORTMODEL_H +#define KDEVPLATFORM_VARIABLESORTMODEL_H + +#include + +class QModelIndex; + +namespace KDevelop +{ + class VariableSortProxyModel : public QSortFilterProxyModel + { + Q_OBJECT + + public: + VariableSortProxyModel(QObject *parent = 0); + + protected: + bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; + }; +} + +#endif diff --git a/debugger/variable/variablesortmodel.cpp b/debugger/variable/variablesortmodel.cpp new file mode 100644 --- /dev/null +++ b/debugger/variable/variablesortmodel.cpp @@ -0,0 +1,46 @@ +/* + * KDevelop Debugger Support + * + * Copyright 2016 Mikhail Ivchenko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "variablesortmodel.h" + +#include +#include + +namespace KDevelop +{ + +VariableSortProxyModel::VariableSortProxyModel(QObject *parent) +: QSortFilterProxyModel( parent ) +{ +} + +bool VariableSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + QCollator collator; + collator.setNumericMode( true ); + collator.setCaseSensitivity( Qt::CaseInsensitive ); + QString leftString = sourceModel()->data( left ).toString(); + QString rightString = sourceModel()->data( right ).toString(); + int result = 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_);