Author: dmacvicar
Date: Mon Dec 15 23:59:27 2008
New Revision: 54151
URL: http://svn.opensuse.org/viewcvs/yast?rev=54151&view=rev
Log:
quite progress, will post a screenshot soon
Modified:
branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h
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/yqmodulesmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp?rev=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.cpp Mon Dec 15 23:59:27 2008
@@ -22,14 +22,13 @@
#include "kcategorizedview_p.h"
#include // trunc on C99 compliant systems
-//#include // trunc for not C99 compliant systems
+#include // trunc for not C99 compliant systems
#include <QPainter>
#include <QScrollBar>
#include <QPaintEvent>
-#include <iostream>
-//#include
+#include
#include "kcategorydrawer.h"
#include "kcategorizedsortfilterproxymodel.h"
@@ -58,8 +57,6 @@
const QModelIndexList &KCategorizedView::Private::intersectionSet(const QRect &rect)
{
- std::cout << "&KCategorizedView::Private::intersectionSet" << std::endl;
-
QModelIndex index;
QRect indexVisualRect;
@@ -82,7 +79,6 @@
int middle = (top + bottom) / 2;
while (bottom <= top)
{
- std::cout << "bottom <= top" << std::endl;
middle = (top + bottom) / 2;
index = proxyModel->index(middle, 0);
@@ -129,8 +125,9 @@
QString curCategory = elementsInfo[index.row()].category;
QRect retRect;
-
- if (listView->flow() == QListView::LeftToRight)
+ const bool leftToRightFlow = (listView->flow() == QListView::LeftToRight);
+
+ if (leftToRightFlow)
{
if (listView->layoutDirection() == Qt::LeftToRight)
{
@@ -154,17 +151,17 @@
int itemHeight;
int itemWidth;
- if (listView->gridSize().isEmpty() && (listView->flow() == QListView::LeftToRight))
+ if (listView->gridSize().isEmpty() && leftToRightFlow)
{
itemHeight = biggestItemSize.height();
itemWidth = biggestItemSize.width();
}
- else if (listView->flow() == QListView::LeftToRight)
+ else if (leftToRightFlow)
{
itemHeight = listView->gridSize().height();
itemWidth = listView->gridSize().width();
}
- else if (listView->gridSize().isEmpty() && (listView->flow() == QListView::TopToBottom))
+ else if (listView->gridSize().isEmpty() && !leftToRightFlow)
{
itemHeight = biggestItemSize.height();
itemWidth = listView->viewport()->width() - listView->spacing() * 2;
@@ -185,7 +182,7 @@
int column;
int row;
- if (listView->flow() == QListView::LeftToRight)
+ if (leftToRightFlow)
{
column = elementsInfo[index.row()].relativeOffsetToCategory % elementsPerRow;
row = elementsInfo[index.row()].relativeOffsetToCategory / elementsPerRow;
@@ -254,8 +251,12 @@
}
else
{
- retRect.setHeight(qMin(listView->sizeHintForIndex(heightIndex).height(),
- listView->gridSize().height()));
+ const QSize sizeHint = listView->sizeHintForIndex(heightIndex);
+ if (sizeHint.width() < itemWidth && leftToRightFlow) {
+ retRect.setWidth(sizeHint.width());
+ retRect.moveLeft(retRect.left() + (itemWidth - sizeHint.width()) / 2);
+ }
+ retRect.setHeight(qMin(sizeHint.height(), listView->gridSize().height()));
}
return retRect;
@@ -268,7 +269,7 @@
listView->viewport()->width() - listView->spacing() * 2,
0);
- if (!proxyModel->rowCount() || !categories.contains(category))
+ if (!proxyModel || !categoryDrawer || !proxyModel->isCategorizedModel() || !proxyModel->rowCount() || !categories.contains(category))
return QRect();
QModelIndex index = proxyModel->index(0, 0, QModelIndex());
@@ -332,25 +333,26 @@
const QRect &KCategorizedView::Private::cacheIndex(const QModelIndex &index)
{
QRect rect = visualRectInViewport(index);
- elementsPosition[index.row()] = rect;
+ QHash::iterator it = elementsPosition.insert(index.row(), rect);
- return elementsPosition[index.row()];
+ return *it;
}
// We're sure categoriesPosition doesn't contain category
const QRect &KCategorizedView::Private::cacheCategory(const QString &category)
{
QRect rect = visualCategoryRectInViewport(category);
- categoriesPosition[category] = rect;
+ QHash::iterator it = categoriesPosition.insert(category, rect);
- return categoriesPosition[category];
+ return *it;
}
const QRect &KCategorizedView::Private::cachedRectIndex(const QModelIndex &index)
{
- if (elementsPosition.contains(index.row())) // If we have it cached
+ QHash::const_iterator it = elementsPosition.constFind(index.row());
+ if (it != elementsPosition.constEnd()) // If we have it cached
{ // return it
- return elementsPosition[index.row()];
+ return *it;
}
else // Otherwise, cache it
{ // and return it
@@ -360,9 +362,10 @@
const QRect &KCategorizedView::Private::cachedRectCategory(const QString &category)
{
- if (categoriesPosition.contains(category)) // If we have it cached
+ QHash::const_iterator it = categoriesPosition.constFind(category);
+ if (it != categoriesPosition.constEnd()) // If we have it cached
{ // return it
- return categoriesPosition[category];
+ return *it;
}
else // Otherwise, cache it and
{ // return it
@@ -395,8 +398,6 @@
const QStyleOption &option,
QPainter *painter)
{
- std::cout << "KCategorizedView::Private::drawNewCategory" << std::endl;
-
if (!index.isValid())
{
return;
@@ -459,7 +460,7 @@
void KCategorizedView::Private::drawDraggedItems(QPainter *painter)
{
- QStyleOptionViewItemV3 option = listView->viewOptions();
+ QStyleOptionViewItemV4 option = listView->viewOptions();
option.state &= ~QStyle::State_MouseOver;
foreach (const QModelIndex &index, listView->selectionModel()->selectedIndexes())
{
@@ -498,7 +499,8 @@
modelCategorized = proxyModel->isCategorizedModel();
}
}
- else if (proxyModel && categoryDrawer && proxyModel->isCategorizedModel())
+
+ if (proxyModel && categoryDrawer && proxyModel->isCategorizedModel())
{
updateScrollbars();
}
@@ -551,9 +553,6 @@
void KCategorizedView::setModel(QAbstractItemModel *model)
{
-
- std::cout << "KCategorizedView::setModel" << std::endl;
-
d->lastSelection = QItemSelection();
d->forcedSelectionPosition = 0;
d->elementsInfo.clear();
@@ -569,17 +568,11 @@
if (d->proxyModel)
{
- std::cout << "d->proxyModel1" << std::endl;
-
QObject::disconnect(d->proxyModel,
SIGNAL(layoutChanged()),
this, SLOT(slotLayoutChanged()));
QObject::disconnect(d->proxyModel,
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotLayoutChanged()));
-
- QObject::disconnect(d->proxyModel,
SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(rowsRemoved(QModelIndex,int,int)));
}
@@ -590,8 +583,6 @@
if (d->proxyModel)
{
- std::cout << "d->proxyModel2" << std::endl;
-
d->modelSortRole = d->proxyModel->sortRole();
d->modelSortColumn = d->proxyModel->sortColumn();
d->modelSortOrder = d->proxyModel->sortOrder();
@@ -603,17 +594,11 @@
this, SLOT(slotLayoutChanged()));
QObject::connect(d->proxyModel,
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotLayoutChanged()));
-
- QObject::connect(d->proxyModel,
SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(rowsRemoved(QModelIndex,int,int)));
if (d->proxyModel->rowCount())
{
- std::cout << "rowCount()" << std::endl;
-
d->layoutChanged(true);
}
}
@@ -665,10 +650,6 @@
this, SLOT(slotLayoutChanged()));
QObject::disconnect(d->proxyModel,
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotLayoutChanged()));
-
- QObject::disconnect(d->proxyModel,
SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(rowsRemoved(QModelIndex,int,int)));
}
@@ -679,10 +660,6 @@
this, SLOT(slotLayoutChanged()));
QObject::connect(d->proxyModel,
- SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotLayoutChanged()));
-
- QObject::connect(d->proxyModel,
SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(rowsRemoved(QModelIndex,int,int)));
}
@@ -714,7 +691,7 @@
QModelIndex index;
- QModelIndexList item = d->intersectionSet(QRect(point, point));
+ const QModelIndexList item = d->intersectionSet(QRect(point, point));
if (item.count() == 1)
{
@@ -745,25 +722,21 @@
void KCategorizedView::paintEvent(QPaintEvent *event)
{
-
- std::cout << "KCategorizedView::paintEvent" << std::endl;
-
if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategorizedModel())
{
QListView::paintEvent(event);
- std::cout << "..return" << std::endl;
return;
}
- QStyleOptionViewItemV3 option = viewOptions();
+ bool alternatingRows = alternatingRowColors();
+
+ QStyleOptionViewItemV4 option = viewOptions();
option.widget = this;
if (wordWrap())
{
- option.features |= QStyleOptionViewItemV2::WrapText;
+ option.features |= QStyleOptionViewItemV4::WrapText;
}
- std::cout << ".";
-
QPainter painter(viewport());
QRect area = event->rect();
const bool focus = (hasFocus() || viewport()->hasFocus()) &&
@@ -772,12 +745,25 @@
const bool enabled = (state & QStyle::State_Enabled) != 0;
painter.save();
- std::cout << ",";
QModelIndexList dirtyIndexes = d->intersectionSet(area);
+ bool alternate = false;
+ if (dirtyIndexes.count())
+ {
+ alternate = dirtyIndexes[0].row() % 2;
+ }
foreach (const QModelIndex &index, dirtyIndexes)
{
- std::cout << "foreach QModelIndex..." << std::endl;
+ if (alternatingRows && alternate)
+ {
+ option.features |= QStyleOptionViewItemV4::Alternate;
+ alternate = false;
+ }
+ else if (alternatingRows)
+ {
+ option.features &= ~QStyleOptionViewItemV4::Alternate;
+ alternate = true;
+ }
option.state = state;
option.rect = visualRect(index);
@@ -808,10 +794,7 @@
option.state |= QStyle::State_Editing;
}
- // we are only interested to give the mouse over feedback when no
- // dragging is happening (ereslibre)
- if ((index == d->hovered) && !d->mouseButtonPressed &&
- (this->state() == QAbstractItemView::NoState))
+ if (index == d->hovered)
option.state |= QStyle::State_MouseOver;
else
option.state &= ~QStyle::State_MouseOver;
@@ -819,15 +802,11 @@
itemDelegate(index)->paint(&painter, option, index);
}
- std::cout << "-";
-
// Redraw categories
- QStyleOptionViewItem otherOption;
+ QStyleOptionViewItemV4 otherOption;
bool intersectedInThePast = false;
foreach (const QString &category, d->categories)
{
-
- std::cout << "..Redraw cat (foreach)" << std::endl;
otherOption = option;
otherOption.rect = d->categoryVisualRect(category);
otherOption.state &= ~QStyle::State_MouseOver;
@@ -847,7 +826,6 @@
// this is doable because we know that categories are correctly ordered on the list
}
}
- std::cout << "+";
if ((selectionMode() != SingleSelection) && (selectionMode() != NoSelection))
{
@@ -890,8 +868,6 @@
}
painter.restore();
-
- std::cout << "!" << std::endl;
}
void KCategorizedView::resizeEvent(QResizeEvent *event)
@@ -1062,7 +1038,7 @@
return;
}
- QModelIndexList item = d->intersectionSet(QRect(event->pos(), event->pos()));
+ const QModelIndexList item = d->intersectionSet(QRect(event->pos(), event->pos()));
if (item.count() == 1)
{
@@ -1076,7 +1052,7 @@
const QString previousHoveredCategory = d->hoveredCategory;
d->mousePosition = event->pos();
- d->hoveredCategory = QString();
+ d->hoveredCategory.clear();
// Redraw categories
foreach (const QString &category, d->categories)
@@ -1143,7 +1119,10 @@
QListView::mousePressEvent(event);
- d->lastSelection = selectionModel()->selection();
+ if (selectionModel())
+ {
+ d->lastSelection = selectionModel()->selection();
+ }
viewport()->update(d->categoryVisualRect(d->hoveredCategory));
}
@@ -1169,7 +1148,8 @@
{
foreach(const QString &category, d->categories)
{
- if (d->categoryVisualRect(category).contains(event->pos()))
+ if (d->categoryVisualRect(category).contains(event->pos()) &&
+ selectionModel())
{
QItemSelection selection = selectionModel()->selection();
QModelIndexList indexList = d->categoriesIndexes[category];
@@ -1225,7 +1205,7 @@
void KCategorizedView::leaveEvent(QEvent *event)
{
d->hovered = QModelIndex();
- d->hoveredCategory = QString();
+ d->hoveredCategory.clear();
QListView::leaveEvent(event);
}
@@ -1237,7 +1217,9 @@
// ARGB window so it is no transparent. Use QAbstractItemView when
// this is fixed on Qt.
// QAbstractItemView::startDrag(supportedActions);
-#if !defined(DOLPHIN_DRAGANDDROP)
+#if defined(DOLPHIN_DRAGANDDROP)
+ Q_UNUSED(supportedActions);
+#else
QListView::startDrag(supportedActions);
#endif
@@ -1273,8 +1255,12 @@
{
return;
}
+
+ d->hovered = indexAt(event->pos());
+#if !defined(DOLPHIN_DRAGANDDROP)
d->drawDraggedItems();
+#endif
}
void KCategorizedView::dragLeaveEvent(QDragLeaveEvent *event)
@@ -1328,7 +1314,8 @@
if (!elementsPerRow)
elementsPerRow++;
- QModelIndex current = selectionModel()->currentIndex();
+ QModelIndex current = selectionModel() ? selectionModel()->currentIndex()
+ : QModelIndex();
if (!current.isValid())
{
@@ -1345,10 +1332,6 @@
return current;
}
- else if (!current.isValid())
- {
- return QModelIndex();
- }
QString lastCategory = d->categories.first();
QString theCategory = d->categories.first();
@@ -1601,6 +1584,9 @@
int start,
int end)
{
+ Q_UNUSED(parent);
+ Q_UNUSED(start);
+ Q_UNUSED(end);
if (d->proxyModel && d->categoryDrawer && d->proxyModel->isCategorizedModel())
{
// Force the view to update all elements
@@ -1661,4 +1647,31 @@
QListView::currentChanged(current, previous);
}
+void KCategorizedView::dataChanged(const QModelIndex &topLeft,
+ const QModelIndex &bottomRight)
+{
+ if (topLeft == bottomRight)
+ {
+ d->cacheIndex(topLeft);
+ }
+ else
+ {
+ const int columnStart = topLeft.column();
+ const int columnEnd = bottomRight.column();
+ const int rowStart = topLeft.row();
+ const int rowEnd = bottomRight.row();
+
+ for (int row = rowStart; row <= rowEnd; ++row)
+ {
+ for (int column = columnStart; column <= columnEnd; ++column)
+ {
+ d->cacheIndex(d->proxyModel->index(row, column));
+ }
+ }
+ }
+
+ QListView::dataChanged(topLeft, bottomRight);
+ slotLayoutChanged();
+}
+
#include "kcategorizedview.moc"
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h?rev=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorizedview.h Mon Dec 15 23:59:27 2008
@@ -23,22 +23,21 @@
#include
-//#include
+#include
class KCategoryDrawer;
/**
* @short Item view for listing items
*
- * KCategorizedView allows you to use it as it were a QListView. You can add an
- * itemCategorizer to it, so your items became categorized depending on the
- * KItemCategorizer inherited class rules.
+ * KCategorizedView allows you to use it as it were a QListView.
+ * Subclass KCategorizedSortFilterProxyModel to provide category information for items.
*
- * @see KItemCategorizer, KSortFilterProxyModel
+ * @see KCategorizedSortFilterProxyModel
*
* @author Rafael Fernández López
*/
-class KCategorizedView
+class KDEUI_EXPORT KCategorizedView
: public QListView
{
Q_OBJECT
@@ -110,10 +109,12 @@
virtual void currentChanged(const QModelIndex ¤t,
const QModelIndex &previous);
+ virtual void dataChanged(const QModelIndex &topLeft,
+ const QModelIndex &bottomRight);
private:
class Private;
- Private *d;
+ Private *const d;
};
#endif // KCATEGORIZEDVIEW_H
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp?rev=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.cpp Mon Dec 15 23:59:27 2008
@@ -22,11 +22,12 @@
#include <QPainter>
#include <QStyleOption>
-#include <iostream>
+#include <QApplication>
+#include
+#include
-//#include
-#include "kcategorizedsortfilterproxymodel.h"
+#define HORIZONTAL_HINT 3
KCategoryDrawer::KCategoryDrawer()
{
@@ -43,8 +44,6 @@
{
const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
- std::cout << "KCategoryDrawer::drawCategory" << std::endl;
-
QColor color;
if (option.state & QStyle::State_Selected)
@@ -59,33 +58,13 @@
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
- if (option.state & QStyle::State_Selected)
- {
- QColor selected = option.palette.color(QPalette::Highlight);
-
- QLinearGradient gradient(option.rect.topLeft(),
- option.rect.bottomRight());
- gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
- : 1, selected);
- gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
- : 0, Qt::transparent);
-
- painter->fillRect(option.rect, gradient);
- }
- else if (option.state & QStyle::State_MouseOver)
- {
- QColor hover = option.palette.color(QPalette::Highlight).light();
- hover.setAlpha(88);
-
- QLinearGradient gradient(option.rect.topLeft(),
- option.rect.bottomRight());
- gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
- : 1, hover);
- gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
- : 0, Qt::transparent);
-
- painter->fillRect(option.rect, gradient);
- }
+ QStyleOptionViewItemV4 viewOptions;
+ viewOptions.rect = option.rect;
+ viewOptions.palette = option.palette;
+ viewOptions.direction = option.direction;
+ viewOptions.state = option.state;
+ viewOptions.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
+ QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewOptions, painter, 0);
QFont painterFont = painter->font();
painterFont.setWeight(QFont::Bold);
@@ -108,7 +87,10 @@
painter->setPen(color);
- painter->drawText(option.rect, Qt::AlignVCenter | Qt::AlignLeft,
+ QRect textRect(option.rect);
+ textRect.setLeft(textRect.left() + HORIZONTAL_HINT);
+ textRect.setRight(textRect.right() - HORIZONTAL_HINT);
+ painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignLeft,
metrics.elidedText(category, Qt::ElideRight, option.rect.width()));
painter->restore();
Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h?rev=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/kcategorydrawer.h Mon Dec 15 23:59:27 2008
@@ -21,13 +21,13 @@
#ifndef KCATEGORYDRAWER_H
#define KCATEGORYDRAWER_H
-//#include
+#include
class QPainter;
class QModelIndex;
class QStyleOption;
-class KCategoryDrawer
+class KDEUI_EXPORT KCategoryDrawer
{
public:
KCategoryDrawer();
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=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.cpp Mon Dec 15 23:59:27 2008
@@ -13,11 +13,16 @@
#include <QSettings>
#include <QDir>
#include <QIcon>
-#include <QHash>
+#include <QMap>
#include <QFileSystemWatcher>
#include "yqdesktopfilesmodel.h"
+typedef QMap PropertyMap;
+typedef QMapIterator PropertyMapIterator;
+typedef QMap PropertyMapCache;
+typedef QMapIterator PropertyMapCacheIterator;
+
// private data of the model
class YQDesktopFilesModel::Private
{
@@ -26,7 +31,9 @@
{}
~Private()
- {}
+ {
+ qWarning() << "Destroy!";
+ }
// directories to read
QStringList desktop_dirs;
@@ -37,7 +44,8 @@
QStringList desktop_files;
// already read data
// row -> ( key -> data )
- QHash > cache;
+ PropertyMapCache cache;
+
QFileSystemWatcher watcher;
};
@@ -50,7 +58,6 @@
SLOT(slotDesktopFilesDirectoryChanged( const QString & ) ) );
addDesktopFilesPath(dir);
- readDesktopFilesDirectories();
}
YQDesktopFilesModel::~YQDesktopFilesModel()
@@ -58,8 +65,24 @@
delete d;
}
-QModelIndex YQDesktopFilesModel::indexForValue( const QString &key, const QVariant &value )
+QModelIndex YQDesktopFilesModel::indexForValue( const QString &key, const QVariant &value ) const
{
+ PropertyMapCache &cache = d->cache;
+
+ PropertyMapCacheIterator it(cache);
+ //qDebug() << "cache has "<< cache.size() << " entries";
+
+ while ( it.hasNext() )
+ {
+ it.next();
+
+ int row = it.key();
+ PropertyMap data(it.value());
+ if ( data.contains(key) && ( data.value(key) == value ) )
+ return index(row, 0);
+ }
+
+ qWarning() << "No index for key: " << key << " value: " << value.toString();
return QModelIndex();
}
@@ -68,6 +91,7 @@
d->desktop_dirs << dir;
d->watcher.addPath(dir);
readDesktopFilesDirectories();
+ readDesktopFiles();
}
void YQDesktopFilesModel::addIconPath( const QString &dir )
@@ -78,14 +102,73 @@
void YQDesktopFilesModel::slotDesktopFilesDirectoryChanged( const QString &path )
{
//emit dataChanged();
- reset();
+ //reset();
+}
+
+/**
+ * read a YaST group .desktop file
+ */
+PropertyMap readDesktopFile( const QString &filename )
+{
+ // desktop file data
+ PropertyMap data;
+
+ QSettings desktopFile( filename, QSettings::IniFormat );
+
+ // check if parsing was correct
+ if ( desktopFile.status() != QSettings::NoError )
+ {
+ qWarning() << "Error reading desktop file " << filename;
+ return data;
+ }
+
+ desktopFile.beginGroup( "Desktop Entry" );
+
+ QStringList keys(desktopFile.allKeys());
+ QStringListIterator keyit(keys);
+ while (keyit.hasNext())
+ {
+ QString key(keyit.next());
+ data.insert(key, desktopFile.value(key));
+ }
+
+ qDebug() << filename << " read with " << data.size() << " keys";
+
+ return data;
+}
+
+void YQDesktopFilesModel::readDesktopFiles()
+{
+ //d->desktop_files.clear();
+ d->cache.clear();
+
+ QStringListIterator it(d->desktop_files);
+
+ int count = 0;
+ int success = 0;
+
+ while ( it.hasNext() )
+ {
+ QString filename = it.next();
+ // first lookup in cache
+ PropertyMap data;
+
+ data = readDesktopFile(filename);
+ if ( ! data.empty() )
+ {
+ d->cache.insert(count, data);
+ count++;
+
+ success++;
+ }
+ }
+ qDebug() << success << " desktop files read";
}
void YQDesktopFilesModel::readDesktopFilesDirectories()
{
//d->desktop_dirs.clear();
d->desktop_files.clear();
- d->cache.clear();
QStringListIterator dirs(d->desktop_dirs);
@@ -108,7 +191,7 @@
}
}
- qDebug() << d->desktop_files.size() << " groups";
+ qDebug() << d->desktop_files.size() << " desktop files in total";
}
}
@@ -127,43 +210,11 @@
return createIndex(row, column);
}
-/**
- * read a YaST group .desktop file
- */
-QHash readDesktopFile( const QString &filename )
-{
- // desktop file data
- QHash data;
-
- QSettings desktopFile( filename, QSettings::IniFormat );
-
- // check if parsing was correct
- if ( desktopFile.status() != QSettings::NoError )
- {
- qWarning() << "Error reading desktop file " << filename;
- return data;
- }
-
- desktopFile.beginGroup( "Desktop Entry" );
-
- QStringList keys(desktopFile.allKeys());
- QStringListIterator keyit(keys);
- while (keyit.hasNext())
- {
- QString key(keyit.next());
- data.insert(key, desktopFile.value(key));
- }
-
-
- return data;
-}
-
-
QVariant YQDesktopFilesModel::data( const QModelIndex &index, int role ) const
{
-
QStringListIterator it(d->desktop_files);
-
+ PropertyMapCache &cache = d->cache;
+
int count = 0;
while ( it.hasNext() )
{
@@ -171,18 +222,24 @@
if ( count == index.row() )
{
// first lookup in cache
- QHash data;
- if ( d->cache.contains(index.row()) )
+ PropertyMap data;
+ if ( cache.contains(index.row()) )
{
- data = d->cache.value(index.row());
+ data = cache.value(index.row());
}
else
{
data = readDesktopFile(filename);
if ( data.empty() )
+ {
+ qWarning() << "No data for " << filename;
return QVariant();
- d->cache.insert(index.row(), data);
+ }
+
+ qDebug() << "caching item " << index.row();
+
+ cache.insert(index.row(), data);
}
// check the role and column
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=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqdesktopfilesmodel.h Mon Dec 15 23:59:27 2008
@@ -60,12 +60,14 @@
* returns the index of the first item for which the key has
* the provided value
*/
- QModelIndex indexForValue( const QString &key, const QVariant &value );
+ QModelIndex indexForValue( const QString &key, const QVariant &value ) const;
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
virtual QModelIndex parent( const QModelIndex & index ) const;
protected:
void readDesktopFilesDirectories();
+ void readDesktopFiles();
+
protected slots:
void slotDesktopFilesDirectoryChanged( const QString &path );
private:
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=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp Mon Dec 15 23:59:27 2008
@@ -30,7 +30,7 @@
QModelIndex YQModuleGroupsModel::indexForGroupId( const QString &groupid ) const
{
- return QModelIndex();
+ return indexForValue( "X-SuSE-YaST-Group", groupid );
}
QVariant YQModuleGroupsModel::data( const QModelIndex &index, int role ) const
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=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp Mon Dec 15 23:59:27 2008
@@ -22,6 +22,8 @@
~Private()
{}
YQModuleGroupsModel groupsModel;
+ QMap groupidCache;
+ QMap groupnameCache;
};
@@ -38,16 +40,44 @@
{
}
+QString YQModulesModel::groupIdForIndex( const QModelIndex &idx ) const
+{
+ QModelIndex newindex = index( idx.row(), Group);
+
+ if ( d->groupidCache.contains(idx.row()) )
+ return d->groupidCache[idx.row()];
+
+ QString groupid = data( newindex, Qt::UserRole ).toString();
+ d->groupidCache[idx.row()] = groupid;
+
+ return groupid;
+}
+
+QString YQModulesModel::groupNameForIndex( const QModelIndex &idx ) const
+{
+ if ( d->groupnameCache.contains(idx.row()) )
+ return d->groupnameCache[idx.row()];
+
+ // what is the groupid for this module
+ QString groupid = groupIdForIndex(idx);
+ // what is the index of that groupid in the Group model
+ QModelIndex groupindex = d->groupsModel.indexForGroupId( groupid );
+ // now find the DisplayRole of that group
+ QString name = d->groupsModel.data( groupindex ).toString();
+
+ d->groupnameCache[idx.row()] = name;
+ return name;
+}
+
QVariant YQModulesModel::data( const QModelIndex &index, int role ) const
{
if ( role == KCategorizedSortFilterProxyModel::CategoryDisplayRole )
{
- return QVariant("Foo");
-
+ return groupNameForIndex(index);
}
else if ( role == KCategorizedSortFilterProxyModel::CategorySortRole )
{
- return QVariant(32);
+ return groupNameForIndex(index);
}
else
{
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=54151&r1=54150&r2=54151&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h Mon Dec 15 23:59:27 2008
@@ -37,7 +37,22 @@
YQModulesModel( QObject * parent = 0 );
~YQModulesModel();
+ /**
+ * reimplemented from YQDesktopFilesModel
+ */
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
+
+ /**
+ * returns the group id for item with index
+ */
+ QString groupIdForIndex( const QModelIndex &index ) const;
+
+ /**
+ * returns the group name for item with index
+ */
+ QString groupNameForIndex( const QModelIndex &index ) const;
+
+
private:
class Private;
Private *const d;
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org