kdelibs, KPopupMenu self-delete

Michael Buesch mbuesch at freenet.de
Thu May 19 16:23:22 BST 2005


Hi,

What about adding a "self-delete on hide" functionality
to KPopupMenu:

Index: kdeui/kpopupmenu.h
===================================================================
--- kdeui/kpopupmenu.h  (revision 415731)
+++ kdeui/kpopupmenu.h  (working copy)
@@ -241,6 +241,18 @@
      */
     Qt::ButtonState state() const;
 
+    /**
+     * Returns whether this KPopupMenu is deleted on hide event.
+     * Default: false
+     * @since 4.0
+     */
+    bool deleteOnHide() const;
+    /**
+     * Set whether this KPopupMenu should be deleted on hide event.
+     * @since 4.0
+     */
+    void setDeleteOnHide(bool del);
+
 signals:
     /**
      * connect to this signal to be notified when a context menu is about to be shown
Index: kdeui/kpopupmenu.cpp
===================================================================
--- kdeui/kpopupmenu.cpp        (revision 415731)
+++ kdeui/kpopupmenu.cpp        (working copy)
@@ -125,6 +125,7 @@
         : noMatches(false)
         , shortcuts(false)
         , autoExec(false)
+        , deleteOnHide(false)
         , lastHitIndex(-1)
         , state(Qt::NoButton)
         , m_ctxMenu(0)
@@ -143,6 +144,7 @@
     bool noMatches : 1;
     bool shortcuts : 1;
     bool autoExec : 1;
+    bool deleteOnHide : 1;
 
     QString keySeq;
     QString originalText;
@@ -264,6 +266,16 @@
     return tmp;
 }
 
+bool KPopupMenu::deleteOnHide() const
+{
+    return d->deleteOnHide;
+}
+
+void KPopupMenu::setDeleteOnHide(bool del)
+{
+    d->deleteOnHide = del;
+}
+
 /**
  * This is re-implemented for keyboard navigation.
  */
@@ -661,6 +673,8 @@
         d->m_ctxMenu->hide();
         blockSignals(false);
     }
+    if (d->deleteOnHide)
+        deleteLater();
 }
 /**
  * end of RMB menus on menus support




I do something like this in my code, to write code like this:

void Foo::showContextMenu_slot(/*...*/)
{
	KPopupMenu *menu = new KPopupMenu(this);
	menu->setDeleteOnHide(true);
	// menu->insertItem(......
	menu->popup(pos);
	// no need to care about deleting the context menu.
}

Is there a way to do this, which is already provided by QT/KDE?


-- 
Greetings, Michael


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050519/3b0819f6/attachment.sig>


More information about the kde-core-devel mailing list