Author: kmachalkova
Date: Wed May 13 16:56:35 2009
New Revision: 57157
URL: http://svn.opensuse.org/viewcvs/yast?rev=57157&view=rev
Log:
Sort groups list by X-SuSE-YaST-SortKey (compare
group name if sor keys are identical - unfortunately
it may happen)
Modified:
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp?rev=57157&r1=57156&r2=57157&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp Wed May 13 16:56:35 2009
@@ -9,47 +9,12 @@
| |
\---------------------------------------------------------------------*/
-#include <QDebug>
#include <QSettings>
#include <QDir>
#include <QIcon>
#include <QMap>
-#include <QFileSystemWatcher>
#include "yqdesktopfilesmodel.h"
-
-typedef QMap PropertyMap;
-typedef QMapIterator PropertyMapIterator;
-// desktop file -> properties
-typedef QMap PropertyMapCache;
-typedef QMapIterator PropertyMapCacheIterator;
-
-// private data of the model
-class YQDesktopFilesModel::Private
-{
-public:
- Private()
- {}
-
- ~Private()
- {
- qWarning() << "Destroy!";
- }
-
- // directories to read
- QStringList desktop_dirs;
-
- QStringList icon_dirs;
-
- // list of .desktop files read from disk
- QStringList desktop_files;
- // already read data
- // row -> ( key -> data )
- PropertyMapCache cache;
-
- QFileSystemWatcher watcher;
-};
-
YQDesktopFilesModel::YQDesktopFilesModel( const QString &dir, QObject * parent )
: QAbstractItemModel(parent)
@@ -242,6 +207,8 @@
else
qSort(d->desktop_files.begin(), d->desktop_files.end(), qGreater<QString>());
emit layoutChanged();
+ qDebug() << "sorting" << endl;
+ return;
}
QVariant YQDesktopFilesModel::data( const QModelIndex &index, int role ) const
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h?rev=57157&r1=57156&r2=57157&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h Wed May 13 16:56:35 2009
@@ -13,7 +13,9 @@
#define YQDESKTOPFILESMODEL_H
#include <QAbstractItemModel>
+#include <QDebug>
#include <QStringList>
+#include <QFileSystemWatcher>
/**
* this class represents a directory with .desktop files
@@ -22,6 +24,15 @@
*
* @author Duncan Mac-Vicar P.
*/
+
+typedef QMap PropertyMap;
+typedef QMapIterator PropertyMapIterator;
+// desktop file -> properties
+typedef QMap PropertyMapCache;
+typedef QMapIterator PropertyMapCacheIterator;
+
+class cmp;
+
class YQDesktopFilesModel : public QAbstractItemModel
{
Q_OBJECT
@@ -75,12 +86,33 @@
protected:
void readDesktopFilesDirectories();
void readDesktopFiles();
+
+ class Private {
+ public:
+
+ Private() {}
+
+ ~Private() { qWarning() << "Destroy!"; }
+
+ // directories to read
+ QStringList desktop_dirs;
+
+ QStringList icon_dirs;
+
+ // list of .desktop files read from disk
+ QStringList desktop_files;
+
+ // already read data
+ // row -> ( key -> data )
+ PropertyMapCache cache;
+
+ QFileSystemWatcher watcher;
+ };
+
+ Private *const d;
protected slots:
void slotDesktopFilesDirectoryChanged( const QString &path );
-private:
- class Private;
- Private *const d;
};
#endif
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp?rev=57157&r1=57156&r2=57157&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp Wed May 13 16:56:35 2009
@@ -19,11 +19,23 @@
#define DEFAULT_GROUP_ICON "yast-default-group.png"
+bool paircmp( QPair p1, QPair p2)
+{
+ //bool operator() ( QPair p1, QPair p2)
+ //{
+ if ( p1.first != p2.first )
+ return p1.first < p2.first ;
+ else
+ return p1.second < p2.second;
+ //}
+};
+
YQModuleGroupsModel::YQModuleGroupsModel( QObject * parent )
: YQDesktopFilesModel( GROUPS_DESKTOP_DIR, parent)
{
addIconPath("/usr/share/YaST2/theme/current/icons/32x32/apps");
addIconPath("/usr/share/icons/hicolor/32x32/apps");
+ reindex();
}
YQModuleGroupsModel::~YQModuleGroupsModel()
@@ -44,6 +56,40 @@
}
+int YQModuleGroupsModel::sortKeyForGroup ( QString &fname )
+{
+ int pos = d->desktop_files.indexOf( fname );
+ QModelIndex idx = index( pos, SortKey );
+ int skey = data( idx, Qt::UserRole ).toInt();
+ return skey;
+}
+
+void YQModuleGroupsModel::reindex()
+{
+ // pairs, because sort keys don't have to be unique :(
+ QList< QPair< int, QString> > sortKeys;
+
+ QStringListIterator it( d->desktop_files );
+
+ while (it.hasNext())
+ {
+ QString dfile(it.next());
+ sortKeys.append( qMakePair( sortKeyForGroup(dfile), dfile) );
+ }
+
+ qSort(sortKeys.begin(), sortKeys.end(), paircmp);
+
+ d->desktop_files.clear();
+ QPair p;
+ foreach( p , sortKeys )
+ {
+ qDebug() << p.second;
+ d->desktop_files << p.second;
+ }
+
+}
+
+
QVariant YQModuleGroupsModel::data( const QModelIndex &index, int role ) const
{
return YQDesktopFilesModel::data(index, role);
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h?rev=57157&r1=57156&r2=57157&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h Wed May 13 16:56:35 2009
@@ -21,6 +21,7 @@
*
* @author Duncan Mac-Vicar P.
*/
+
class YQModuleGroupsModel : public YQDesktopFilesModel
{
Q_OBJECT
@@ -39,11 +40,15 @@
*/
QModelIndex indexForGroupId( const QString &groupid ) const;
+ int sortKeyForGroup( QString &fname );
+
/**
* Returns the group id for a given group
*/
QString groupId( const QModelIndex &idx ) const;
+private:
+ void reindex();
};
#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org