kaction, plug(), isPlugged()

Aaron J. Seigo aseigo at olympusproject.org
Thu Jul 25 05:57:17 BST 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi...

playing with plugging kactions i came across the follow problem, and
i'm not sure what to do about it:

i want to plug an action into a widget once, and exactly once. when the block
that does the plugging gets run (which may be several times over the course
of the object's life) the action may or may not have already been plugged
into the target widget. so i figured i'd check isPlugged().. and there the
fun began.

on success KAction::plug returns containerCount() - 1

isPlugged comes in three variations:

 isPlugged()
 isPlugged(QWidget* container, QWidget* representative)
 isPlugged (QWidget* container, int index)

well, isPlugged() isn't what i want because that return true if it exists
with an accell, which in this case it does.

but whatever, i have two more options to try out. the version that
wants a representative QWidget was a bit mystifying. i tried several
different QWidgets in a guess-and-test methodology since the documentation
was vague on the matter. then i resorted to reading the KAction code.

apparently nothing ever calls the version of the addContainer that provides
a representative widget, so i still have no idea what a representative is, nor
can i get it to work using this version of isPlugged() ... why is this
version of isPlugged even there? (and for that matter addContainer(QWidget,
QWidget)?)

the third version of isPlugged takes a container (no problem there, i know
what the container is) and an id. so i catch the return from ::plug(..) and
tossed it in as the second parameter.... that doesn't work.

so i look at the code.

bool KAction::isPlugged( const QWidget *container, int id ) const
{
  int i = findContainer( container );
  return ( i > -1 && itemId( i ) == id );
}

hrm... so it takes the index of the container, and checks up on the itemId
associated with that container. ok. that's the second parameter handed to
addContainer(..) from inside of plug(..) ... that doesn't help any since
plug(..) returns:

  d->m_containers.count() - 1;

so, mumbling to myself that i really shouldn't have to keep some extra bit of
state information around, i try taking the return from ::plug() and pop it
into itemID(int index) to get the id, which just hangs the app with:
ASSERT: "i <= nodes" in /usr/lib/qt3/include/qvaluelist.h (335)

how is one supposed to use isPlugged()???

why isn't there a nice simple isPlugged(QWidget* container)? i don't
really care if it is the 2nd, 3rd, or 100th item in the container. i just
want to know if it has been plugged in there. without keeping superfluous
state information around.

obviously it wouldn't be able to be made virtual for BC reasons like the
other isPlugged's, but i don't think that would really matter. of course it
could be made virtual in a few years when KDE4 is started on.

p.s. i added isPlugged(QWidget* container) to my local copy of KAction and
things are happy here =)

p.p.s. this is also why the home button isn't in kfd yet ;-)

- --
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

"Everything should be made as simple as possible, but not simpler"
    - Albert Einstein

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9P4Ut1rcusafx20MRAvKSAKCR1BX9UKqABdQBfndsRufOiO2RNQCcDcmg
/zGS3VFbr4f+mmHT0TqQzro=
=0b+/
-----END PGP SIGNATURE-----





More information about the kde-core-devel mailing list