Mailinglist Archive: yast-commit (595 mails)

< Previous Next >
[yast-commit] r54218 - in /branches/tmp/tgoettlicher/yast2cc_rewrite/src: main_window.cpp yqdesktopfilesmodel.cpp yqdesktopfilesmodel.h yqmodulesmodel.cpp yqmodulesmodel.h
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Tue, 16 Dec 2008 23:37:43 -0000
  • Message-id: <20081216233744.284DBB0ED1@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Wed Dec 17 00:37:43 2008
New Revision: 54218

URL: http://svn.opensuse.org/viewcvs/yast?rev=54218&view=rev
Log:

- fix clicking on module captures the right item (forgot to map to
source model)
- convert cache to filename -> data map on desktop files model
- misc fixes


Modified:
branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h

Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp?rev=54218&r1=54217&r2=54218&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp Wed Dec 17
00:37:43 2008
@@ -34,6 +34,10 @@
{
public:
Private()
+ : modmodel(0L)
+ , groupview(0L)
+ , modview(0L)
+ , kcsfpm(0L)
{
}
~Private()
@@ -43,7 +47,8 @@
YQModulesModel *modmodel;
QListView *groupview;
KCategorizedView * modview;
-
+ // category proxy model
+ KCategorizedSortFilterProxyModel * kcsfpm;
};

MainWindow::MainWindow()
@@ -90,14 +95,14 @@

// init the models
d->modmodel = new YQModulesModel(this);
- KCategorizedSortFilterProxyModel * kcsfpm = new YQModulesProxyModel( this
);
- kcsfpm->setCategorizedModel( true );
- kcsfpm->setSourceModel( d->modmodel );
+ d->kcsfpm = new YQModulesProxyModel( this );
+ d->kcsfpm->setCategorizedModel( true );
+ d->kcsfpm->setSourceModel( d->modmodel );

//kcsfpm->setFilterRole( KCModuleModel::UserFilterRole );
//kcsfpm->setFilterCaseSensitivity( Qt::CaseInsensitive );
- kcsfpm->sort( 0 );
- d->modview->setModel( kcsfpm );
+ d->kcsfpm->sort( 0 );
+ d->modview->setModel( d->kcsfpm );

// Setup Dock Widget with groups
QDockWidget *groupdock = new QDockWidget(this);
@@ -110,6 +115,9 @@

connect( d->groupview, SIGNAL( pressed( const QModelIndex & ) ),
SLOT( slotGroupPressed( const QModelIndex & ) ) );
+
+ connect( d->modview, SIGNAL( pressed( const QModelIndex & ) ),
+ SLOT( slotModulePressed( const QModelIndex & ) ) );
}

void MainWindow::slotGroupPressed( const QModelIndex &index )
@@ -120,12 +128,18 @@
qDebug() << "Scroll to :" <<
d->modmodel->groupsModel()->data(index).toString();
qDebug() << " 1st item :" << d->modmodel->data(modidx).toString();
if ( modidx.isValid() )
- d->modview->scrollTo(modidx);
+ d->modview->scrollTo(d->kcsfpm->mapFromSource(modidx));
}

void MainWindow::slotModulePressed( const QModelIndex &index )
{
-
+ // map the categorized index to the modules model index
+ QModelIndex srcidx = d->kcsfpm->mapToSource(index);
+ if ( ! srcidx.isValid() )
+ return;
+
+ qDebug() << "Module Click:" << d->modmodel->data(srcidx).toString();
+ qDebug() << "-> " << srcidx.row() << " : " <<
d->modmodel->propertyValue(srcidx, "GenericName").toString();
}

void MainWindow::initActions()

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=54218&r1=54217&r2=54218&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp
(original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp Wed
Dec 17 00:37:43 2008
@@ -20,8 +20,9 @@

typedef QMap<QString, QVariant> PropertyMap;
typedef QMapIterator<QString, QVariant> PropertyMapIterator;
-typedef QMap<int, PropertyMap > PropertyMapCache;
-typedef QMapIterator<int, PropertyMap> PropertyMapCacheIterator;
+// desktop file -> properties
+typedef QMap<QString, PropertyMap > PropertyMapCache;
+typedef QMapIterator<QString, PropertyMap> PropertyMapCacheIterator;

// private data of the model
class YQDesktopFilesModel::Private
@@ -67,19 +68,23 @@

QModelIndex YQDesktopFilesModel::indexForValue( const QString &key, const
QVariant &value ) const
{
- PropertyMapCache &cache = d->cache;
-
- PropertyMapCacheIterator it(cache);
+ PropertyMapCacheIterator it(d->cache);
//qDebug() << "cache has "<< cache.size() << " entries";

while ( it.hasNext() )
{
- it.next();
-
- int row = it.key();
+ it.next();
+ // filename is the key of the iterator
+ //QString filename = it.key();
PropertyMap data(it.value());
if ( data.contains(key) && ( data.value(key) == value ) )
- return index(row, 0);
+ {
+ // we found a match, lets figure out the position of
+ // the file in the list
+ int pos = d->desktop_files.indexOf(it.key());
+ if ( pos != -1 )
+ return index(pos, 0);
+ }
}

qWarning() << "No index for key: " << key << " value: " <<
value.toString();
@@ -156,11 +161,11 @@
data = readDesktopFile(filename);
if ( ! data.empty() )
{
- d->cache.insert(count, data);
- count++;
-
+ d->cache.insert(filename, data);
+ qDebug() << filename << " has index " << count;
success++;
}
+ count++;
}
qDebug() << success << " desktop files read";
}
@@ -176,7 +181,7 @@
{
// read group desktop files
QDir dir( dirs.next() + "/", "*.desktop" );
-
+
if ( ! dir.exists() )
{
qWarning() << "Directory " << dir.absolutePath() << " does not
exist";
@@ -210,88 +215,82 @@
return createIndex(row, column);
}

+QVariant YQDesktopFilesModel::propertyValue( const QModelIndex &index, const
QString &key ) const
+{
+ // first lookup in cache
+ if ( index.row() > d->desktop_files.size() - 1 )
+ return QVariant();
+
+ // get file at position
+ QString filename = d->desktop_files.at(index.row());
+
+ PropertyMap data;
+ if ( d->cache.contains(filename) )
+ {
+ data = d->cache.value(filename);
+ if ( data.contains(key) )
+ return data.value(key);
+ }
+ return QVariant();
+}
+
+void YQDesktopFilesModel::sort( int, Qt::SortOrder order )
+{
+ emit layoutAboutToBeChanged();
+ if (order == Qt::AscendingOrder)
+ qSort(d->desktop_files.begin(), d->desktop_files.end(),
qLess<QString>());
+ else
+ qSort(d->desktop_files.begin(), d->desktop_files.end(),
qGreater<QString>());
+ emit layoutChanged();
+}
+
QVariant YQDesktopFilesModel::data( const QModelIndex &index, int role ) const
{
QStringListIterator it(d->desktop_files);
- PropertyMapCache &cache = d->cache;

- int count = 0;
- while ( it.hasNext() )
+ // check the role and column
+ if ( role == Qt::DisplayRole )
{
- QString filename = it.next();
- if ( count == index.row() )
+ return propertyValue( index, "Name" );
+ }
+ else if ( role == Qt::DecorationRole )
+ {
+ QString icon = propertyValue( index, "Icon" ).toString();
+ QRegExp extension( "\\.(png|jpg)$", Qt::CaseInsensitive );
+ if ( icon.indexOf( extension ) < 0 ) // no .png or .jpg extension?
+ icon += ".png"; // assume .png
+ QStringListIterator it(d->icon_dirs);
+ while (it.hasNext())
{
- // first lookup in cache
- PropertyMap data;
- if ( cache.contains(index.row()) )
- {
- data = cache.value(index.row());
- }
- else
- {
- data = readDesktopFile(filename);
-
- if ( data.empty() )
- {
- qWarning() << "No data for " << filename;
- return QVariant();
- }
-
- qDebug() << "caching item " << index.row();
-
- cache.insert(index.row(), data);
- }
-
- // check the role and column
- if ( role == Qt::DisplayRole )
- {
- return data.value("Name");
- }
- else if ( role == Qt::DecorationRole )
+ QString icondir(it.next());
+ if ( QFile::exists(icondir + "/" + icon) )
{
- QString icon = data.value("Icon").toString();
- QRegExp extension( "\\.(png|jpg)$", Qt::CaseInsensitive );
- if ( icon.indexOf( extension ) < 0 ) // no .png or .jpg
extension?
- icon += ".png"; // assume .png
- QStringListIterator it(d->icon_dirs);
- while (it.hasNext())
- {
- QString icondir(it.next());
- if ( QFile::exists(icondir + "/" + icon) )
- {
- return QIcon(icondir + "/" + icon);
- }
- }
- return QVariant();
+ return QIcon(icondir + "/" + icon);
}
- else if ( role == Qt::UserRole )
- {
- // user role has app specific data
- switch ( index.column() )
- {
- case Name:
- return data.value("Name");
- case Group:
- return data.value("X-SuSE-YaST-Group");
- case Icon:
- return data.value("Icon");
- case SortKey:
- return data.value("X-SuSE-YaST-SortKey");
- default:
- return QVariant();
- }
- }
- else
- {
- return QVariant();
- }
}
- else
+ return QVariant();
+ }
+ else if ( role == Qt::UserRole )
+ {
+ // user role has app specific data
+ switch ( index.column() )
{
- count++;
- }
+ case Name:
+ return propertyValue( index, "Name" );
+ case Group:
+ return propertyValue( index, "X-SuSE-YaST-Group" );
+ case Icon:
+ return propertyValue( index, "Icon" );
+ case SortKey:
+ return propertyValue( index, "X-SuSE-YaST-SortKey" );
+ default:
+ return QVariant();
+ }
}
-
+ else
+ {
+ return QVariant();
+ }
return QVariant();
}


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=54218&r1=54217&r2=54218&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h
(original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h Wed Dec
17 00:37:43 2008
@@ -62,13 +62,21 @@
*/
QModelIndex indexForValue( const QString &key, const QVariant &value )
const;

+ /**
+ * returns the desktop file property for the given key
+ */
+ QVariant propertyValue( const QModelIndex &index, const QString &key )
const;
+
virtual QVariant data( const QModelIndex &index, int role =
Qt::DisplayRole ) const;
+
+ virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
+
virtual QModelIndex parent( const QModelIndex & index ) const;
protected:
void readDesktopFilesDirectories();
void readDesktopFiles();

- protected slots:
+protected slots:
void slotDesktopFilesDirectoryChanged( const QString &path );
private:
class Private;

Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp?rev=54218&r1=54217&r2=54218&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp Wed Dec 17
00:37:43 2008
@@ -68,6 +68,12 @@
return indexForValue( "X-SuSE-YaST-Group", grpid );
}

+Qt::ItemFlags YQModulesModel::flags ( const QModelIndex & index ) const
+{
+ //qDebug() << "requesting flags for module";
+ return Qt::ItemIsEnabled;
+}
+
QModelIndex YQModulesModel::groupForModule( const QModelIndex &idx) const
{
if ( d->groupCache.contains(idx) )

Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h?rev=54218&r1=54217&r2=54218&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h Wed Dec 17
00:37:43 2008
@@ -45,6 +45,12 @@
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole
) const;

/**
+ * reimplement flags to make items non selectable and enabled
+ * depending if they are installed
+ */
+ virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
+
+ /**
* group index for a given model
*/
QModelIndex groupForModule( const QModelIndex &index) const;

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages