Mailinglist Archive: yast-commit (595 mails)

< Previous Next >
[yast-commit] r54193 - in /branches/tmp/tgoettlicher/yast2cc_rewrite/src: main_window.cpp main_window.h yqmodulegroupsmodel.cpp yqmodulegroupsmodel.h yqmodulesmodel.cpp yqmodulesmodel.h
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Tue, 16 Dec 2008 15:31:26 -0000
  • Message-id: <20081216153127.32E53316A0@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Tue Dec 16 16:31:26 2008
New Revision: 54193

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

Move some methods around where they make sense.
we have a dock with groups too


Modified:
branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.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=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.cpp Tue Dec 16
16:31:26 2008
@@ -13,51 +13,125 @@

#include <QLayout>
#include <QLabel>
+#include <QToolBar>
+#include <QLabel>
+#include <QLineEdit>
+#include <QDockWidget>
+#include <QListView>
#include <QDebug>

#include "kcategorizedsortfilterproxymodel.h"
#include "kcategorizedview.h"
#include "kcategorydrawer.h"
#include "yqmodulesproxymodel.h"
+
#include "yqmodulesmodel.h"
+#include "yqmodulegroupsmodel.h"

#include "moduleiconitem.h"

-MainWindow::MainWindow() : QMainWindow()
+class MainWindow::Private
+{
+public:
+ Private()
+ {
+ }
+ ~Private()
+ {
+ }
+
+ YQModulesModel *modmodel;
+ QListView *groupview;
+ KCategorizedView * modview;
+
+};
+
+MainWindow::MainWindow()
+ : QMainWindow()
+ , d(new Private)
{
qDebug();

+ // Tool bar
+ QToolBar *toolbar = new QToolBar(this);
+
+ // Search Widget
+ QWidget *searchWidget = new QWidget(this);
+ QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget);
+ QLabel *searchLabel = new QLabel(searchWidget);
+ searchLabel->setText("Search:");
+ searchLayout->addWidget(searchLabel);
+ QLineEdit *searchField = new QLineEdit(searchWidget);
+ searchLayout->addWidget(searchField);
+
+ // Add search widget to toolbar
+ toolbar->addWidget(searchWidget);
+ addToolBar(toolbar);
+
+ // Central widget
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
-
QHBoxLayout *layout = new QHBoxLayout;
centralWidget->setLayout(layout);

+ // setup central widget
+ d->modview = new KCategorizedView( this );
KCategoryDrawer * drawer = new KCategoryDrawer;
- KCategorizedView * tv = new KCategorizedView( this );
-
- layout->addWidget(tv);
+
+ layout->addWidget(d->modview);

- tv->setSelectionMode(QAbstractItemView::SingleSelection);
+ d->modview->setSelectionMode(QAbstractItemView::SingleSelection);
// tv->setSpacing(KDialog::spacingHint());
- tv->setCategoryDrawer( drawer );
- tv->setViewMode( QListView::IconMode );
- tv->setItemDelegate( new ModuleIconItemDelegate( this ) );
- tv->setMouseTracking( true );
- tv->viewport()->setAttribute( Qt::WA_Hover );
- YQModulesModel *model = new YQModulesModel(this);
+ d->modview->setCategoryDrawer( drawer );
+ d->modview->setViewMode( QListView::IconMode );
+ d->modview->setItemDelegate( new ModuleIconItemDelegate( this ) );
+ d->modview->setMouseTracking( true );
+ d->modview->viewport()->setAttribute( Qt::WA_Hover );
+
+ // init the models
+ d->modmodel = new YQModulesModel(this);
KCategorizedSortFilterProxyModel * kcsfpm = new YQModulesProxyModel( this
);
kcsfpm->setCategorizedModel( true );
- kcsfpm->setSourceModel( model );
+ kcsfpm->setSourceModel( d->modmodel );
+
//kcsfpm->setFilterRole( KCModuleModel::UserFilterRole );
//kcsfpm->setFilterCaseSensitivity( Qt::CaseInsensitive );
kcsfpm->sort( 0 );
- tv->setModel( kcsfpm );
+ d->modview->setModel( kcsfpm );
+
+ // Setup Dock Widget with groups
+ QDockWidget *groupdock = new QDockWidget(this);
+ d->groupview = new QListView(groupdock);
+ d->groupview->setModel(d->modmodel->groupsModel());
+
+ groupdock->setWidget(d->groupview);
+
+ addDockWidget(Qt::LeftDockWidgetArea, groupdock);
+
+ connect( d->groupview, SIGNAL( pressed( const QModelIndex & ) ),
+ SLOT( slotGroupPressed( const QModelIndex & ) ) );
+}
+
+void MainWindow::slotGroupPressed( const QModelIndex &index )
+{
+ qDebug() << "Group Click";
+ // scroll to the category in the main view
+ QModelIndex modidx = d->modmodel->firstModuleInGroup(index);
+ qDebug() << "Scroll to :" <<
d->modmodel->groupsModel()->data(index).toString();
+ qDebug() << " 1st item :" << d->modmodel->data(modidx).toString();
+ if ( modidx.isValid() )
+ d->modview->scrollTo(modidx);
+}
+
+void MainWindow::initActions()
+{
+
}


MainWindow::~MainWindow()
{
+ delete d;
}

#include "main_window.moc"

Modified: branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h
URL:
http://svn.opensuse.org/viewcvs/yast/branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h?rev=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/main_window.h Tue Dec 16
16:31:26 2008
@@ -32,7 +32,13 @@
MainWindow();
~MainWindow();

-public slots:
+protected slots:
+ void slotGroupPressed( const QModelIndex &index );
+protected:
+ void initActions();
+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=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp
(original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.cpp Tue
Dec 16 16:31:26 2008
@@ -22,6 +22,8 @@
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");
}

YQModuleGroupsModel::~YQModuleGroupsModel()
@@ -33,6 +35,15 @@
return indexForValue( "X-SuSE-YaST-Group", groupid );
}

+QString YQModuleGroupsModel::groupId( const QModelIndex &idx ) const
+{
+ QModelIndex grpid = index( idx.row(), Group);
+ // retrieve the groupid
+ QString groupid = data( grpid, Qt::UserRole ).toString();
+ return groupid;
+}
+
+
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=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h
(original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulegroupsmodel.h Tue Dec
16 16:31:26 2008
@@ -26,14 +26,6 @@
Q_OBJECT
public:

- enum UserRoleData
- {
- RawName,
- SortKey,
- Hidden,
- LastColumn
- };
-
YQModuleGroupsModel( QObject * parent = 0 );
~YQModuleGroupsModel();

@@ -46,6 +38,12 @@
* the group id, which you may had obtain in the modules model for example.
*/
QModelIndex indexForGroupId( const QString &groupid ) const;
+
+ /**
+ * Returns the group id for a given group
+ */
+ QString groupId( const QModelIndex &idx ) const;
+
};

#endif

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=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.cpp Tue Dec 16
16:31:26 2008
@@ -9,6 +9,8 @@
| |
\---------------------------------------------------------------------*/

+#include <QDebug>
+
#include "yqmodulesmodel.h"
#include "yqmodulesproxymodel.h"

@@ -18,12 +20,19 @@
{
public:
Private()
- {}
+ : groupsModel(new YQModuleGroupsModel)
+ {
+
+ }
+
~Private()
- {}
- YQModuleGroupsModel groupsModel;
+ {
+ delete groupsModel;
+ }
+
+ YQModuleGroupsModel *groupsModel;
QMap<int, QString> groupidCache;
- QMap<int, QString> groupnameCache;
+ QMap<QModelIndex, QModelIndex> groupCache;
};


@@ -40,46 +49,55 @@
{
}

-QString YQModulesModel::groupIdForIndex( const QModelIndex &idx ) const
+YQModuleGroupsModel * YQModulesModel::groupsModel() const
{
- QModelIndex newindex = index( idx.row(), Group);
-
- if ( d->groupidCache.contains(idx.row()) )
- return d->groupidCache[idx.row()];
+ return d->groupsModel;
+}
+
+QModelIndex YQModulesModel::firstModuleInGroup( const QModelIndex &index )
const
+{
+ // what is the name of that group?
+ QString grpid = groupsModel()->groupId(index);
+
+ if ( grpid.isEmpty() )
+ return QModelIndex();

- QString groupid = data( newindex, Qt::UserRole ).toString();
- d->groupidCache[idx.row()] = groupid;
+ qDebug() << "look element with value " << grpid;

- return groupid;
+ // Look first item that has property set to that group id.
+ return indexForValue( "X-SuSE-YaST-Group", grpid );
}

-QString YQModulesModel::groupNameForIndex( const QModelIndex &idx ) const
+QModelIndex YQModulesModel::groupForModule( const QModelIndex &idx) const
{
- if ( d->groupnameCache.contains(idx.row()) )
- return d->groupnameCache[idx.row()];
+ if ( d->groupCache.contains(idx) )
+ return d->groupCache[idx];
+
+ // create an index for the module group's string id
+ QModelIndex modgrpid = index( idx.row(), Group);
+ // retrieve the groupid
+ QString groupid = data( modgrpid, Qt::UserRole ).toString();
+
+ QModelIndex groupindex = d->groupsModel->indexForGroupId( groupid );

- // 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->groupCache[idx] = groupindex;

- d->groupnameCache[idx.row()] = name;
- return name;
+ return groupindex;
}

QVariant YQModulesModel::data( const QModelIndex &index, int role ) const
{
+ // this 2 roles are required if the model is expected to work
+ // with the categorized view
if ( role == KCategorizedSortFilterProxyModel::CategoryDisplayRole )
{
- return groupNameForIndex(index);
+ return groupsModel()->data( groupForModule(index) );
}
else if ( role == KCategorizedSortFilterProxyModel::CategorySortRole )
{
- return groupNameForIndex(index);
+ return groupsModel()->data( groupForModule(index) );
}
- else
+ else // otherwise just use the parent class
{
return YQDesktopFilesModel::data(index, role);
}

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=54193&r1=54192&r2=54193&view=diff
==============================================================================
--- branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h (original)
+++ branches/tmp/tgoettlicher/yast2cc_rewrite/src/yqmodulesmodel.h Tue Dec 16
16:31:26 2008
@@ -15,6 +15,8 @@
#include <QStringList>
#include "yqdesktopfilesmodel.h"

+class YQModuleGroupsModel;
+
/**
* this class represents YaST module groups
* so they can be used in any GUI item
@@ -43,15 +45,21 @@
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole
) const;

/**
- * returns the group id for item with index
+ * group index for a given model
*/
- QString groupIdForIndex( const QModelIndex &index ) const;
+ QModelIndex groupForModule( const QModelIndex &index) const;

/**
* returns the group name for item with index
*/
- QString groupNameForIndex( const QModelIndex &index ) const;
+ //QString groupNameForIndex( const QModelIndex &index ) const;
+
+ QModelIndex firstModuleInGroup( const QModelIndex &index ) const;

+ /**
+ * the groups model this modules model is using
+ */
+ YQModuleGroupsModel * groupsModel() const;

private:
class Private;

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

< Previous Next >
This Thread
  • No further messages