[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/systemsettings
From:       Ben Cooksley <sourtooth () gmail ! com>
Date:       2009-05-10 9:22:16
Message-ID: 1241947336.380523.20623.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 965988 by bcooksley:

Fix drawing of the tree
Switch to a more flexible exceptions system which actually does what the docs say
Ensure we don't crash when we have entered the tree view
More whitespace fixes

BUG: 192145

 M  +6 -3      classic/ClassicMode.cpp  
 M  +1 -17     core/MenuItem.cpp  
 M  +4 -19     core/MenuItem.h  
 M  +27 -24    core/MenuModel.cpp  
 M  +10 -2     core/MenuModel.h  
 M  +3 -1      icons/IconMode.cpp  


--- trunk/KDE/kdebase/workspace/systemsettings/classic/ClassicMode.cpp #965987:965988
@@ -72,7 +72,9 @@
 
 ClassicMode::~ClassicMode()
 {
-    delete d->classicWidget;
+    if( !d->classicTree ) {
+        delete d->classicWidget;
+    }
     delete d;
 }
 
@@ -80,7 +82,9 @@
 {
     // Create the model
     d->model = new MenuModel( rootItem(), this );
-    d->model->addException( rootItem() );
+    foreach( MenuItem * child, rootItem()->children() ) {
+        d->model->addException( child );
+	}
     // Create the model
     d->proxyModel = new MenuProxyModel( this );
     d->proxyModel->setSourceModel( d->model );
@@ -125,7 +129,6 @@
 void ClassicMode::expandColumns()
 {
     d->classicTree->resizeColumnToContents(0);
-    d->classicTree->resizeColumnToContents(1);
 }
 
 void ClassicMode::searchChanged( const QString& text )
--- trunk/KDE/kdebase/workspace/systemsettings/core/MenuItem.cpp #965987:965988
@@ -7,7 +7,7 @@
    published by the Free Software Foundation; either version 2 of
    the License or (at your option) version 3 or any later version
    accepted by the membership of KDE e.V. (or its successor approved
-   by the membership of KDE e.V.), which shall act as a proxy 
+   by the membership of KDE e.V.), which shall act as a proxy
    defined in Section 14 of version 3 of the license.
 
    This program is distributed in the hope that it will be useful,
@@ -37,7 +37,6 @@
 
     MenuItem *parent;
     QList<MenuItem*> children;
-    QList<MenuItem*> grandChildren;
     bool menu;
     QString name;
     int weight;
@@ -53,17 +52,12 @@
 
     if ( d->parent ) {
         d->parent->children().append( this );
-        MenuItem * grandParent = d->parent->parent();
-        if( grandParent ) {
-            grandParent->grandChildren().append(this);
-        }
     }
 }
 
 MenuItem::~MenuItem()
 {
     qDeleteAll( d->children );
-    d->grandChildren.clear();
     delete d;
 }
 
@@ -77,11 +71,6 @@
     return d->children.at(index);
 }
 
-MenuItem * MenuItem::grandChild( int index )
-{
-    return d->grandChildren.at(index);
-}
-
 QStringList MenuItem::keywords()
 {
     QStringList listOfKeywords;
@@ -103,11 +92,6 @@
     return d->children;
 }
 
-QList<MenuItem*>& MenuItem::grandChildren() const
-{
-    return d->grandChildren;
-}
-
 KService::Ptr& MenuItem::service() const
 {
     return d->service;
--- trunk/KDE/kdebase/workspace/systemsettings/core/MenuItem.h #965987:965988
@@ -33,14 +33,14 @@
 /**
  * @brief Provides a specific item in the list of modules or categories
  *
- * This provides convienent access to the list of modules, providing information \
about them  + * This provides convienent access to the list of modules, providing \
                information about them
  * such as name, module information and its service object.\n
  * This is created automatically by System Settings, and is shared among all plugins \
                and so should not
  * be modified under any circumstances.\n
- * 
+ *
  * System Settings creates it in a tree like manner, with categories containing \
                subcategories and modules,
  * and subcategories repeating this.\n
- * 
+ *
  * The service object must be set, unless it is the top level item, otherwise using \
                applications
  * will crash when attempting to sort the children by weight
  *
@@ -81,14 +81,6 @@
     MenuItem * child( int index );
 
     /**
-     * Provides the MenuItem for the grand child at the specified index.
-     *
-     * @param index The index of the grand child.
-     * @returns The MenuItem object of the specified grand child.
-     */
-    MenuItem * grandChild( int index );
- 
-    /**
      * Returns the list of keywords, which is used for searching the list of \
                categories and modules.
      *
      * @note The parent items share all the keywords of their children.
@@ -111,20 +103,13 @@
     QList<MenuItem*>& children() const;
 
     /**
-     * Provides the list of all grand children this item has. Excludes its children.
-     *
-     * @returns The list of grand children this item has.
-     */
-    QList<MenuItem*>& grandChildren() const;
-
-    /**
      * Returns the service object of this item, which contains useful information \
                about it.
      *
      * @returns The service object of this item if it has been set.
      */
     KService::Ptr& service() const;
 
-    /** 
+    /**
      * Provides the KDE control module information item, which can be used to load \
                control modules
      * by the ModuleView.
      *
--- trunk/KDE/kdebase/workspace/systemsettings/core/MenuModel.cpp #965987:965988
@@ -62,12 +62,8 @@
     } else {
         mi = d->rootItem;
     }
-    if ( mi && d->exceptions.contains(mi) ) {
-        return mi->grandChildren().count();
-    } else if ( mi ) {
-        return mi->children().count();
-    }
-    return 0;
+
+    return childrenList(mi).count();
 }
 
 QVariant MenuModel::data( const QModelIndex &index, int role ) const
@@ -136,13 +132,7 @@
         parentItem = static_cast<MenuItem*>( parent.internalPointer() );
     }
 
-    MenuItem *childItem;
-    if( d->exceptions.contains(parentItem) ) {
-        childItem = parentItem->grandChild( row );
-    } else {
-        childItem = parentItem->child( row );
-    }
-
+    MenuItem *childItem = childrenList(parentItem).value(row);
     if ( childItem ) {
         return createIndex( row, column, childItem );
     } else {
@@ -152,21 +142,19 @@
 
 QModelIndex MenuModel::parent( const QModelIndex &index ) const
 {
-    if ( !index.isValid() ) {
+    MenuItem *childItem = static_cast<MenuItem*>( index.internalPointer() );
+    if( !childItem ) {
         return QModelIndex();
     }
 
-    MenuItem *childItem = static_cast<MenuItem*>( index.internalPointer() );
-    MenuItem *parentItem;
-    MenuItem *grandParent = childItem->parent()->parent();
+    MenuItem * parentItem = childItem->parent();
+    if( d->exceptions.contains(parentItem) ) {
+        parentItem = parentItem->parent();
+    }
+
     int childRow = 0;
-
-    if( d->exceptions.contains(grandParent) ) {
-        parentItem = grandParent;
-        childRow = grandParent->grandChildren().indexOf( parentItem );
-    } else {
-        parentItem = childItem->parent();
-        childRow = grandParent->children().indexOf( parentItem );
+	if( parentItem->parent() ) {
+        childRow = childrenList(parentItem->parent()).indexOf( parentItem );
     }
 
     if ( parentItem == d->rootItem ) {
@@ -175,6 +163,18 @@
     return createIndex( childRow, 0, parentItem );
 }
 
+QList<MenuItem*> MenuModel::childrenList( MenuItem * parent ) const
+{
+    QList<MenuItem*> children = parent->children();
+    foreach( MenuItem * child, children ) {
+        if( d->exceptions.contains( child ) ) {
+            children.removeAll(child);
+            children.append(child->children());
+        }
+    }
+    return children;
+}
+
 MenuItem * MenuModel::rootItem() const
 {
     return d->rootItem;
@@ -182,6 +182,9 @@
 
 void MenuModel::addException( MenuItem * exception )
 {
+    if( exception == d->rootItem ) {
+        return;
+    }
     d->exceptions.append(exception);
 }
 
--- trunk/KDE/kdebase/workspace/systemsettings/core/MenuModel.h #965987:965988
@@ -30,11 +30,11 @@
  * @brief Provides a menu of the MenuItem objects
  *
  * Provides a standardised model to be used with views to display the list of \
                modules in a variety of ways.\n
- * It is recommended to also use this with the MenuProxyModel to provide searching 
+ * It is recommended to also use this with the MenuProxyModel to provide searching
  * and correct ordering of modules.
  *
  * @author Ben Cooksley <ben@eclipse.endoftheinternet.org>
- * @author Will Stephenson <wstephenson@kde.org> 
+ * @author Will Stephenson <wstephenson@kde.org>
  */
 class SYSTEMSETTINGSVIEW_EXPORT MenuModel : public QAbstractItemModel
 {
@@ -148,6 +148,14 @@
      */
     MenuItem* rootItem() const;
 
+    /**
+     * Provides a list of children of an item which has been altered by the \
exceptions list +     *
+     * @param parent The parent of the children desired
+     * @returns The list of children for the item specified
+     */
+    QList<MenuItem*> childrenList( MenuItem * parent ) const;
+
 private:
     class Private;
     Private *const d;
--- trunk/KDE/kdebase/workspace/systemsettings/icons/IconMode.cpp #965987:965988
@@ -106,7 +106,9 @@
 {
     foreach( MenuItem *childItem, rootItem()->children() ) {
         MenuModel *model = new MenuModel( childItem, this );
-        model->addException( childItem );
+        foreach( MenuItem * child, childItem->children() ) {
+            model->addException( child );
+        }
         MenuProxyModel *proxyModel = new MenuProxyModel( this );
         proxyModel->setCategorizedModel( true );
         proxyModel->setSourceModel( model );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic