Author: sh-sh-sh
Date: Tue Sep 9 17:06:45 2008
New Revision: 50914
URL: http://svn.opensuse.org/viewcvs/yast?rev=50914&view=rev
Log:
Added YDialogSpy for interactive introspection of a widget tree
Added:
trunk/libyui/src/YDialogSpy.cc
trunk/libyui/src/YDialogSpy.h
Modified:
trunk/libyui/VERSION
trunk/libyui/package/yast2-libyui.changes
trunk/libyui/src/Makefile.am
Modified: trunk/libyui/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/VERSION?rev=50914&r1=50913&r2=50914&view=diff
==============================================================================
--- trunk/libyui/VERSION (original)
+++ trunk/libyui/VERSION Tue Sep 9 17:06:45 2008
@@ -1 +1 @@
-2.17.7
+2.17.8
Modified: trunk/libyui/package/yast2-libyui.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/package/yast2-libyui.changes?rev=50914&r1=50913&r2=50914&view=diff
==============================================================================
--- trunk/libyui/package/yast2-libyui.changes (original)
+++ trunk/libyui/package/yast2-libyui.changes Tue Sep 9 17:06:45 2008
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Tue Sep 9 17:05:23 CEST 2008 - sh@suse.de
+
+- Added YDialogSpy for interactive introspection of a widget tree
+- V 2.17.8
+
+-------------------------------------------------------------------
Tue Sep 9 16:21:35 CEST 2008 - sh@suse.de
- Made YEvents more robust against attempts of duplicate deletion
Modified: trunk/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/Makefile.am?rev=50914&r1=50913&r2=50914&view=diff
==============================================================================
--- trunk/libyui/src/Makefile.am (original)
+++ trunk/libyui/src/Makefile.am Tue Sep 9 17:06:45 2008
@@ -24,6 +24,7 @@
YOptionalWidgetFactory.cc \
\
YCommandLine.cc \
+ YDialogSpy.cc \
YEvent.cc \
YEventFilter.cc \
YEnvVar.cc \
@@ -107,6 +108,7 @@
YChildrenManager.h \
YColor.h \
YCommandLine.h \
+ YDialogSpy.h \
YEvent.h \
YEventFilter.h \
YEnvVar.h \
Added: trunk/libyui/src/YDialogSpy.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialogSpy.cc?rev=50914&view=auto
==============================================================================
--- trunk/libyui/src/YDialogSpy.cc (added)
+++ trunk/libyui/src/YDialogSpy.cc Tue Sep 9 17:06:45 2008
@@ -0,0 +1,186 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YDialogSpy.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#include <sstream>
+
+#define YUILogComponent "ui-dialog-spy"
+#include "YUILog.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+/**
+ * Custom tree item class to map tree items to widgets
+ **/
+class YWidgetTreeItem: public YTreeItem
+{
+public:
+ YWidgetTreeItem( YWidget * widget,
+ bool isOpen )
+ : YTreeItem( "", isOpen )
+ , _widget( widget )
+ {
+ setWidgetLabel();
+ }
+
+ YWidgetTreeItem( YWidgetTreeItem * parent,
+ YWidget * widget,
+ bool isOpen )
+ : YTreeItem( parent, "", isOpen )
+ , _widget( widget )
+ {
+ setWidgetLabel();
+ }
+
+ virtual ~YWidgetTreeItem() {}
+ YWidget * widget() const { return _widget; }
+
+
+protected:
+
+ void setWidgetLabel()
+ {
+ std::ostringstream str;
+ str << _widget;
+ setLabel( str.str() );
+ }
+
+private:
+ YWidget * _widget;
+};
+
+
+static void fillTree( YWidgetTreeItem * parent,
+ YWidgetListConstIterator begin,
+ YWidgetListConstIterator end,
+ int treeLevel );
+
+
+
+
+struct YDialogSpyPrivate
+{
+ YDialogSpyPrivate()
+ : targetDialog( 0 )
+ , spyDialog( 0 )
+ , widgetTree( 0 )
+ , closeButton( 0 )
+ {}
+
+ YDialog * targetDialog; // Dialog that is being inspected
+ YDialog * spyDialog; // Debug dialog that shows widget data
+ YTree * widgetTree; // Tree widget to show widget hierarchy
+ YPushButton * closeButton;
+};
+
+
+
+YDialogSpy::YDialogSpy( YDialog * targetDialog )
+ : priv( new YDialogSpyPrivate() )
+{
+ if ( ! targetDialog )
+ targetDialog = YDialog::topmostDialog();
+
+ priv->targetDialog = targetDialog;
+ YWidgetFactory * fac = YUI::widgetFactory();
+
+ priv->spyDialog = fac->createPopupDialog();
+ YLayoutBox * vbox = fac->createVBox( priv->spyDialog );
+ YAlignment * minSize = fac->createMinSize( vbox, 50, 20 );
+
+ priv->widgetTree = fac->createTree( minSize, "Widget &Tree" );
+
+ YWidgetTreeItem * rootItem = new YWidgetTreeItem( targetDialog, true );
+ YUI_CHECK_NEW( rootItem );
+ fillTree( rootItem, targetDialog->childrenBegin(), targetDialog->childrenEnd(), 1 );
+ priv->widgetTree->addItem( rootItem );
+ priv->widgetTree->rebuildTree();
+
+ YButtonBox * buttonBox = fac->createButtonBox( vbox );
+ priv->closeButton = fac->createPushButton( buttonBox, "&Close" );
+ priv->closeButton->setRole( YOKButton );
+}
+
+
+YDialogSpy::~YDialogSpy()
+{
+ if ( priv->spyDialog )
+ priv->spyDialog->destroy();
+}
+
+
+void fillTree( YWidgetTreeItem * parent,
+ YWidgetListConstIterator begin,
+ YWidgetListConstIterator end,
+ int treeLevel )
+{
+ for ( YWidgetListConstIterator it = begin; it != end; ++it )
+ {
+ YWidget * widget = *it;
+ YWidgetTreeItem * item = new YWidgetTreeItem( parent, widget, treeLevel < 4 );
+
+ if ( widget->hasChildren() )
+ fillTree( item, widget->childrenBegin(), widget->childrenEnd(), treeLevel+1 );
+ }
+}
+
+
+void YDialogSpy::exec()
+{
+ YUI_CHECK_PTR( priv->spyDialog );
+
+ while ( true )
+ {
+ YEvent * event = priv->spyDialog->waitForEvent();
+
+ if ( event )
+ {
+ if ( event->widget() == priv->closeButton )
+ return;
+
+ if ( event->widget() == priv->widgetTree )
+ {
+ yuiDebug() << "Event from " << event->widget() << endl;
+ }
+ }
+ }
+}
+
+
+void YDialogSpy::showDialogSpy( YDialog * dialog )
+{
+ try
+ {
+ YDialogSpy dialogSpy( dialog );
+ dialogSpy.exec();
+ }
+ catch ( YUIException & exception )
+ {
+ YUI_CAUGHT( exception );
+ }
+}
Added: trunk/libyui/src/YDialogSpy.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YDialogSpy.h?rev=50914&view=auto
==============================================================================
--- trunk/libyui/src/YDialogSpy.h (added)
+++ trunk/libyui/src/YDialogSpy.h Tue Sep 9 17:06:45 2008
@@ -0,0 +1,75 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YDialogSpy.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#ifndef YDialogSpy_h
+#define YDialogSpy_h
+
+#include "ImplPtr.h"
+
+class YDialog;
+class YDialogSpyPrivate;
+
+
+/**
+ * An interactive dialog debugger: Show the structure and content of a dialog
+ * and its widgets.
+ *
+ * This can be invoked by special key combinations:
+ * Ctrl-Alt-Shift-Y in the Qt UI
+ **/
+class YDialogSpy
+{
+public:
+ /**
+ * Show a YDialogSpy for the specified dialog. 0 means "use the topmost
+ * dialog".
+ * This will return only when the user closes the YDialogSpy dialog.
+ **/
+ static void showDialogSpy( YDialog * dialog = 0 );
+
+
+protected:
+ /**
+ * Constructor: Create a YDialogSpy for the specified dialog. 0 means "use
+ * the topmost dialog".
+ *
+ * In most cases it is more useful to use the static showDialogSpy() method
+ * rather than create this dialog directly.
+ **/
+ YDialogSpy( YDialog * dialog = 0 );
+
+ /**
+ * Destructor.
+ **/
+ virtual ~YDialogSpy();
+
+ /**
+ * Execute the event loop. This will only return when the user closes the
+ * YDialogSpy dialog.
+ **/
+ void exec();
+
+
+private:
+
+ ImplPtr<YDialogSpyPrivate> priv;
+};
+
+
+#endif // YDialogSpy_h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org