• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kcategorizedsortfilterproxymodel.cpp

Go to the documentation of this file.
00001 
00022 #include "kcategorizedsortfilterproxymodel.h"
00023 #include "kcategorizedsortfilterproxymodel_p.h"
00024 
00025 #include <limits.h>
00026 
00027 #include <QItemSelection>
00028 #include <QStringList>
00029 #include <QSize>
00030 
00031 #include <kstringhandler.h>
00032 
00033 KCategorizedSortFilterProxyModel::KCategorizedSortFilterProxyModel(QObject *parent)
00034     : QSortFilterProxyModel(parent)
00035     , d(new Private())
00036 
00037 {
00038 }
00039 
00040 KCategorizedSortFilterProxyModel::~KCategorizedSortFilterProxyModel()
00041 {
00042     delete d;
00043 }
00044 
00045 void KCategorizedSortFilterProxyModel::sort(int column, Qt::SortOrder order)
00046 {
00047     d->sortColumn = column;
00048     d->sortOrder = order;
00049 
00050     QSortFilterProxyModel::sort(column, order);
00051 }
00052 
00053 bool KCategorizedSortFilterProxyModel::isCategorizedModel() const
00054 {
00055     return d->categorizedModel;
00056 }
00057 
00058 void KCategorizedSortFilterProxyModel::setCategorizedModel(bool categorizedModel)
00059 {
00060     if (categorizedModel == d->categorizedModel)
00061     {
00062         return;
00063     }
00064 
00065     d->categorizedModel = categorizedModel;
00066 
00067     invalidate();
00068 }
00069 
00070 int KCategorizedSortFilterProxyModel::sortColumn() const
00071 {
00072     return d->sortColumn;
00073 }
00074 
00075 Qt::SortOrder KCategorizedSortFilterProxyModel::sortOrder() const
00076 {
00077     return d->sortOrder;
00078 }
00079 
00080 void KCategorizedSortFilterProxyModel::setSortCategoriesByNaturalComparison(bool sortCategoriesByNaturalComparison)
00081 {
00082     if (sortCategoriesByNaturalComparison == d->sortCategoriesByNaturalComparison)
00083     {
00084         return;
00085     }
00086 
00087     d->sortCategoriesByNaturalComparison = sortCategoriesByNaturalComparison;
00088 
00089     invalidate();
00090 }
00091 
00092 bool KCategorizedSortFilterProxyModel::sortCategoriesByNaturalComparison() const
00093 {
00094     return d->sortCategoriesByNaturalComparison;
00095 }
00096 
00097 int KCategorizedSortFilterProxyModel::naturalCompare(const QString &a,
00098                                                      const QString &b)
00099 {
00100     return KStringHandler::naturalCompare(a, b);
00101 }
00102 
00103 bool KCategorizedSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
00104 {
00105     if (d->categorizedModel)
00106     {
00107         int compare = compareCategories(left, right);
00108 
00109         if (compare > 0) // left is greater than right
00110         {
00111             return false;
00112         }
00113         else if (compare < 0) // left is less than right
00114         {
00115             return true;
00116         }
00117     }
00118 
00119     return subSortLessThan(left, right);
00120 }
00121 
00122 bool KCategorizedSortFilterProxyModel::subSortLessThan(const QModelIndex &left, const QModelIndex &right) const
00123 {
00124     return QSortFilterProxyModel::lessThan(left, right);
00125 }
00126 
00127 int KCategorizedSortFilterProxyModel::compareCategories(const QModelIndex &left, const QModelIndex &right) const
00128 {
00129     QVariant l = (left.model() ? left.model()->data(left, CategorySortRole) : QVariant());
00130     QVariant r = (right.model() ? right.model()->data(right, CategorySortRole) : QVariant());
00131 
00132     Q_ASSERT(l.isValid());
00133     Q_ASSERT(r.isValid());
00134     Q_ASSERT(l.type() == r.type());
00135 
00136     if (l.type() == QVariant::String)
00137     {
00138         QString lstr = l.toString();
00139         QString rstr = r.toString();
00140 
00141         if (d->sortCategoriesByNaturalComparison)
00142         {
00143             return KStringHandler::naturalCompare(lstr, rstr);
00144         }
00145         else
00146         {
00147             if (lstr < rstr)
00148             {
00149                 return -1;
00150             }
00151 
00152             if (lstr > rstr)
00153             {
00154                 return 1;
00155             }
00156 
00157             return 0;
00158         }
00159     }
00160 
00161     qlonglong lint = l.toLongLong();
00162     qlonglong rint = r.toLongLong();
00163 
00164     if (lint < rint)
00165     {
00166         return -1;
00167     }
00168 
00169     if (lint > rint)
00170     {
00171         return 1;
00172     }
00173 
00174     return 0;
00175 }

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal