RFC: An action class to ease implementation of show/hide-like actions
kloecker at kde.org
Fri Sep 17 23:06:26 BST 2010
On Friday 17 September 2010, Aurélien Gâteau wrote:
> On 10/09/2010 23:20, Aurélien Gâteau wrote:
> > 2. I wanted the class to have a boolean state and decided to call
> > it "on". I am not so sure it is a good idea now because I realized
> > QAction already has an "on" property in qt3support. It was renamed
> > to "checked" in Qt4, but it still appears in the DBus API when we
> > expose our actions.
> > 3. The bool parameter in the methods to get/set the
> > icon/text,tooltip is there to make it possible to define those for
> > "off" and "on" values. I dislike however having to use the "using"
> > keyword. Would it be better to use different names?
> Found some time today to work a bit more on this class. I made some
> changes to address the two issues quoted above, now the API looks
> like this:
> class KDEUI_EXPORT KDualAction : public KAction
> KDualAction(const QString &offActionText, QObject *parent);
I don't understand why one can set one of the texts via the c'tor, but
not the other one. Am I missing something or did you forget something?
> explicit KDualAction(QObject *parent);
> void setGuiItemForState(bool, const KGuiItem &item);
> KGuiItem guiItemForState(bool) const;
> void setTextForState(bool, const QString &text);
> QString textForState(bool) const;
> void setIconForState(bool, const QIcon &icon);
> QIcon iconForState(bool) const;
> void setToolTipForState(bool, const QString &tip);
> QString toolTipForState(bool) const;
> bool isActive() const;
> void setActive(bool);
> void silentSetActive(bool);
I suppose this is supposed to set the active state without emitting the
corresponding signal, i.e. it is equivalent to
dualAction->blockSignals( true );
dualAction->setActive( true/false );
dualAction->blockSignals( false );
IMHO something like a silentSetActive() (or using blockSignals()) is
evil because the caller can never know whether there are other listeners
which rely on the signal to be emitted. Therefore, I strongly suggest
removing this method from the class's interface.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 198 bytes
Desc: This is a digitally signed message part.
More information about the kde-core-devel