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

List:       kde-core-devel
Subject:    KDE/kdelibs/kdeui
From:       Michel Hermier <michel.hermier () wanadoo ! fr>
Date:       2006-10-30 7:17:38
Message-ID: 1162192658.102422.23943.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 600280 by hermier:

Commit changes spoken here: \
http://lists.kde.org/?l=kde-core-devel&m=116150457425040&w=2

Make setCurrentAction return sucess or failure, and make the code a little bit more \
strict. Make addAction helper methods return KAction instead of QAction.
Factorized a little the code.

I was able to compile the whole (allready compiling) tree without problem with that \
change, but if you see behaviour change or any problem related to thisange, please \
contact me.

CCMAIL: kde-core-devel@kde.org



 M  +29 -55    kselectaction.cpp  
 M  +12 -5     kselectaction.h  


--- trunk/KDE/kdelibs/kdeui/kselectaction.cpp #600279:600280
@@ -11,6 +11,7 @@
               (C) 2005-2006 Hamish Rodda <rodda@kde.org>
               (C) 2006 Albert Astals Cid <aacid@kde.org>
               (C) 2006 Clarence Dang <dang@kde.org>
+              (C) 2006 Michel Hermier <michel.hermier@gmail.com>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -213,7 +214,7 @@
 
 QAction* KSelectAction::currentAction() const
 {
-  return d->m_actionGroup->checkedAction();
+  return selectableActionGroup()->checkedAction();
 }
 
 int KSelectAction::currentItem() const
@@ -229,31 +230,31 @@
   return QString();
 }
 
-void KSelectAction::setCurrentAction(QAction* action)
+bool KSelectAction::setCurrentAction(QAction* action)
 {
   //kDebug (129) << "KSelectAction::setCurrentAction(" << action << ")" << endl;
-  if (!action) {
-    if (currentAction())
-      currentAction()->setChecked(false);
-
-  } else {
-    action->setChecked(true);
+  if (action) {
+    if (actions().contains(action)) {
+      if (action->isVisible() && action->isEnabled() && action->isCheckable()) {
+        action->setChecked(true);
+        return true;
+      } else
+        kWarning (129) << k_funcinfo << "Action don't have the correct properties to \
be current:" << action->text() << endl; +    } else
+      kWarning (129) << k_funcinfo << "Action don't belong to group:" << \
action->text() << endl; +    return false;
   }
+
+  if (currentAction())
+    currentAction()->setChecked(false);
+
+  return false;
 }
 
 bool KSelectAction::setCurrentItem( int index )
 {
   //kDebug (129) << "KSelectAction::setCurrentIndex(" << index << ")" << endl;
-  if (QAction* a = action(index)) {
-    setCurrentAction(a);
-    return true;
-  }
-
-  //kDebug (129) << "\tdoing the deselect" << endl;
-  if (selectableActionGroup()->checkedAction())
-    selectableActionGroup()->checkedAction()->setChecked(false);
-
-  return false;
+  return setCurrentAction(action(index));
 }
 
 QAction * KSelectAction::action( int index ) const
@@ -291,13 +292,7 @@
 bool KSelectAction::setCurrentAction( const QString & text, Qt::CaseSensitivity cs)
 {
   //kDebug (129) << "KSelectAction::setCurrentAction(" << text << ",cs=" << cs << \
                ")" << endl;
-  if (QAction* a = action(text, cs)) {
-    a->setChecked(true);
-    return true;
-  }
-
-  //kDebug (129) << "\tfailed" << endl;
-  return false;
+  return setCurrentAction(action(text, cs));
 }
 
 void KSelectAction::setComboWidth( int width )
@@ -332,7 +327,6 @@
   //kDebug (129) << "KSelectAction::addAction(" << action << ")" << endl;
 
   action->setActionGroup(selectableActionGroup());
-  action->setCheckable( true );
 
   // Keep in sync with createToolBarWidget()
   foreach (QToolButton* button, d->m_buttons)
@@ -344,9 +338,11 @@
   menu()->addAction(action);
 }
 
-QAction* KSelectAction::addAction(const QString& text)
+KAction* KSelectAction::addAction(const QString& text)
 {
-  QAction* newAction = new QAction(text, selectableActionGroup());
+  KAction* newAction = new KAction(text, parentCollection(), 0);
+  newAction->setCheckable( true );
+  newAction->setShortcutConfigurable(false);
 
   if (!d->m_menuAccelsEnabled) {
     newAction->setText(text);
@@ -357,16 +353,10 @@
   return newAction;
 }
 
-QAction* KSelectAction::addAction(const QIcon& icon, const QString& text)
+KAction* KSelectAction::addAction(const KIcon& icon, const QString& text)
 {
-  QAction* newAction = new QAction(icon, text, selectableActionGroup());
-
-  if (!d->m_menuAccelsEnabled) {
-    newAction->setText(text);
-    newAction->setShortcut(QKeySequence());
-  }
-
-  addAction(newAction);
+  KAction* newAction = addAction(text);
+  newAction->setIcon(icon);
   return newAction;
 }
 
@@ -424,20 +414,6 @@
   actions()[index]->setText( d->makeMenuText( text ) );
 }
 
-static KAction *NewAction (KSelectAction *self, const QString &text)
-{
-  KAction* action = new KAction(text, self->parentCollection(), 0);
-
-  if (!self->menuAccelsEnabled ()) {
-    action->setText(text);
-    action->setShortcut(QKeySequence());
-  }
-
-  action->setShortcutConfigurable(false);
-
-  return action;
-}
-
 void KSelectAction::setItems( const QStringList &lst )
 {
   //kDebug (129) << "KSelectAction::setItems(" << lst << ")" << endl;
@@ -446,8 +422,7 @@
 
   foreach (const QString& string, lst) {
     if ( !string.isEmpty() ) {
-      KAction* action = ::NewAction (this, string);
-      addAction(action);
+      addAction(string);
     } else {
       QAction* action = new QAction(this);
       action->setSeparator(true);
@@ -558,8 +533,7 @@
     triggeringCombo->removeItem (index);
     triggeringCombo->blockSignals (false);
 
-    KAction* newAction = ::NewAction (this, newItemText);
-    addAction (newAction);
+    KAction *newAction = addAction (newItemText);
 
     newAction->trigger();
   } else {
--- trunk/KDE/kdelibs/kdeui/kselectaction.h #600279:600280
@@ -10,6 +10,7 @@
               (C) 2005-2006 Hamish Rodda <rodda@kde.org>
               (C) 2006 Albert Astals Cid <aacid@kde.org>
               (C) 2006 Clarence Dang <dang@kde.org>
+              (C) 2006 Michel Hermier <michel.hermier@gmail.com>
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -256,11 +257,13 @@
     QAction* action(const QString& text, Qt::CaseSensitivity cs = Qt::CaseSensitive) \
const;  
     /**
-     *  Sets the currently checked item.
+     * Sets the currently checked item.
      *
-     *  @param item the QAction to become the currently checked item.
+     * @param item the QAction to become the currently checked item.
+     *
+     * \return \e true if a corresponding action was found and successfully checked.
      */
-    void setCurrentAction(QAction* action);
+    bool setCurrentAction(QAction* action);
 
     /**
      * \overload setCurrentAction(QAction*)
@@ -298,16 +301,20 @@
      *
      * Convenience function which creates an action from \a text and inserts it into
      * the list of selectable actions.
+     *
+     * The newly create is checkable and not user configurable.
      */
-    QAction* addAction(const QString& text);
+    KAction* addAction(const QString& text);
 
     /**
      * \overload addAction(QAction* action)
      *
      * Convenience function which creates an action from \a text and \a icon and \
                inserts it into
      * the list of selectable actions.
+     *
+     * The newly create is checkable and not user configurable.
      */
-    QAction* addAction(const QIcon& icon, const QString& text);
+    KAction* addAction(const KIcon& icon, const QString& text);
 
     /**
      * Remove the specified \a action from this action selector.


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

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