[rkward-cvs] SF.net SVN: rkward: [1134] trunk/rkward/rkward/plugin
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Jan 12 13:51:50 UTC 2007
Revision: 1134
http://svn.sourceforge.net/rkward/?rev=1134&view=rev
Author: tfry
Date: 2007-01-12 05:51:49 -0800 (Fri, 12 Jan 2007)
Log Message:
-----------
Add drop down list for plugins
Modified Paths:
--------------
trunk/rkward/rkward/plugin/Makefile.am
trunk/rkward/rkward/plugin/rkcomponent.h
trunk/rkward/rkward/plugin/rkradio.cpp
trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
Added Paths:
-----------
trunk/rkward/rkward/plugin/rkdropdown.cpp
trunk/rkward/rkward/plugin/rkdropdown.h
Modified: trunk/rkward/rkward/plugin/Makefile.am
===================================================================
--- trunk/rkward/rkward/plugin/Makefile.am 2007-01-12 13:49:44 UTC (rev 1133)
+++ trunk/rkward/rkward/plugin/Makefile.am 2007-01-12 13:51:49 UTC (rev 1134)
@@ -4,11 +4,11 @@
libplugin_a_SOURCES = rkcomponentmap.cpp rkcomponentproperties.cpp rkcomponent.cpp \
rkstandardcomponent.cpp rkvarselector.cpp rkvarslot.cpp rkformula.cpp rkradio.cpp \
rkcheckbox.cpp rkpluginspinbox.cpp rkinput.cpp rkpluginbrowser.cpp rktext.cpp \
- rktabpage.cpp rkstandardcomponentgui.cpp
+ rktabpage.cpp rkstandardcomponentgui.cpp rkdropdown.cpp
noinst_HEADERS = rkcomponentmap.h rkcomponentproperties.h rkcomponent.h \
rkstandardcomponent.h rkvarselector.h rkvarslot.h rkformula.h rkradio.h \
rkcheckbox.h rkpluginspinbox.h rkinput.h rkpluginbrowser.h rktext.h \
- rktabpage.h rkstandardcomponentgui.h
+ rktabpage.h rkstandardcomponentgui.h rkdropdown.h
Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h 2007-01-12 13:49:44 UTC (rev 1133)
+++ trunk/rkward/rkward/plugin/rkcomponent.h 2007-01-12 13:51:49 UTC (rev 1134)
@@ -54,6 +54,7 @@
ComponentBrowser = 2010,
ComponentText = 2011,
ComponentTab = 2012,
+ ComponentDropDown = 2013,
ComponentStandard = 2100,
ComponentUser = 3000 /**< for user expansion */
};
Added: trunk/rkward/rkward/plugin/rkdropdown.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkdropdown.cpp (rev 0)
+++ trunk/rkward/rkward/plugin/rkdropdown.cpp 2007-01-12 13:51:49 UTC (rev 1134)
@@ -0,0 +1,117 @@
+/***************************************************************************
+ rkdropdown.h - description
+ -------------------
+ begin : Fri Jan 12 2007
+ copyright : (C) 2007 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "rkdropdown.h"
+
+#include <qdom.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qcombobox.h>
+
+#include <klocale.h>
+
+#include "../rkglobals.h"
+#include "../misc/xmlhelper.h"
+#include "../debug.h"
+
+RKDropDown::RKDropDown (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
+ RK_TRACE (PLUGIN);
+
+ // create and register properties
+ addChild ("string", string = new RKComponentPropertyBase (this, false));
+ connect (string, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (propertyChanged (RKComponentPropertyBase *)));
+ addChild ("number", number = new RKComponentPropertyInt (this, true, -1));
+ connect (number, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (propertyChanged (RKComponentPropertyBase *)));
+
+ // get xml-helper
+ XMLHelper *xml = XMLHelper::getStaticHelper ();
+
+ // create layout
+ QVBoxLayout *vbox = new QVBoxLayout (this, RKGlobals::spacingHint ());
+
+ QLabel *label = new QLabel (xml->getStringAttribute (element, "label", i18n ("Select one:"), DL_INFO), this);
+ vbox->addWidget (label);
+
+ // create ComboBox
+ box = new QComboBox (false, this);
+
+ // create all the options
+ XMLChildList option_elements = xml->getChildElements (element, "option", DL_ERROR);
+ int selected = 0;
+ int i = 0;
+ for (XMLChildList::const_iterator it = option_elements.begin (); it != option_elements.end (); ++it) {
+ box->insertItem (xml->getStringAttribute (*it, "label", QString::null, DL_ERROR));
+ options.insert (i, xml->getStringAttribute (*it, "value", QString::null, DL_WARNING));
+
+ if (xml->getBoolAttribute (*it, "checked", false, DL_INFO)) {
+ selected = i;
+ }
+
+ ++i;
+ }
+
+ updating = false;
+ number->setIntValue (selected); // will also take care of activating the corret item
+ number->setMin (0);
+ number->setMax (i-1);
+
+ vbox->addWidget (box);
+ connect (box, SIGNAL (activated (int)), this, SLOT (itemSelected (int)));
+}
+
+RKDropDown::~RKDropDown(){
+ RK_TRACE (PLUGIN);
+}
+
+void RKDropDown::propertyChanged (RKComponentPropertyBase *property) {
+ RK_TRACE (PLUGIN);
+
+ if (updating) return;
+
+ int new_id = -1;
+ if (property == string) {
+ new_id = findOption (string->value ());
+ } else if (property == number) {
+ new_id = number->intValue ();
+ } else {
+ RK_ASSERT (false);
+ }
+
+ updating = true;
+ box->setCurrentItem (new_id);
+ updating = false;
+
+ changed ();
+}
+
+void RKDropDown::itemSelected (int id) {
+ RK_TRACE (PLUGIN);
+
+ string->setValue (options[id]);
+ number->setIntValue (id);
+}
+
+int RKDropDown::findOption (const QString &option_string) {
+ RK_TRACE (PLUGIN);
+
+ for (OptionsMap::const_iterator it = options.begin(); it != options.end(); ++it) {
+ if (it.data () == option_string) return (it.key ());
+ }
+ return -1;
+}
+
+#include "rkdropdown.moc"
Added: trunk/rkward/rkward/plugin/rkdropdown.h
===================================================================
--- trunk/rkward/rkward/plugin/rkdropdown.h (rev 0)
+++ trunk/rkward/rkward/plugin/rkdropdown.h 2007-01-12 13:51:49 UTC (rev 1134)
@@ -0,0 +1,57 @@
+/***************************************************************************
+ rkdropdown.h - description
+ -------------------
+ begin : Fri Jan 12 2007
+ copyright : (C) 2007 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef RKDROPDOWN_H
+#define RKDROPDOWN_H
+
+#include "rkcomponent.h"
+#include "rkcomponentproperties.h"
+
+#include <qmap.h>
+
+class QComboBox;
+class QDomElement;
+
+/** This RKPluginWidget provides a group of radio-buttons.
+ *@author Thomas Friedrichsmeier
+ */
+
+class RKDropDown : public RKComponent {
+ Q_OBJECT
+public:
+ RKDropDown (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget);
+ ~RKDropDown ();
+ int type () { return ComponentDropDown; };
+/** Find the option number with the corresponding string. If not found, returns -1
+ at param option_string the option string to search for
+ at returns the id (0, 1, 2...) of the corresponding option, or -1 if not found */
+ int findOption (const QString &option_string);
+ QString value (const QString &modifier) { return (string->value (modifier)); };
+public slots:
+ void itemSelected (int id);
+ void propertyChanged (RKComponentPropertyBase *property);
+private:
+ RKComponentPropertyBase *string;
+ RKComponentPropertyInt *number;
+
+ bool updating; // prevent recursion
+ QComboBox *box;
+ typedef QMap<int, QString> OptionsMap;
+ OptionsMap options;
+};
+
+#endif
Modified: trunk/rkward/rkward/plugin/rkradio.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkradio.cpp 2007-01-12 13:49:44 UTC (rev 1133)
+++ trunk/rkward/rkward/plugin/rkradio.cpp 2007-01-12 13:51:49 UTC (rev 1134)
@@ -2,7 +2,7 @@
rkradio.cpp - description
-------------------
begin : Thu Nov 7 2002
- copyright : (C) 2002, 2006 by Thomas Friedrichsmeier
+ copyright : (C) 2002, 2006, 2007 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -69,16 +69,14 @@
++i;
}
- updating = false;
- number->setIntValue (checked); // will also take care of checking the correct button
- number->setMin (0);
- number->setMax (i-1);
vbox->addWidget (group);
connect (group, SIGNAL (clicked (int)), this, SLOT (buttonClicked (int)));
- // initialize
- buttonClicked (group->selectedId ());
+ updating = false;
+ number->setIntValue (checked); // will also take care of checking the correct button
+ number->setMin (0);
+ number->setMax (i-1);
}
RKRadio::~RKRadio(){
Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2007-01-12 13:49:44 UTC (rev 1133)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp 2007-01-12 13:51:49 UTC (rev 1134)
@@ -40,6 +40,7 @@
#include "rkvarslot.h"
#include "rkformula.h"
#include "rkradio.h"
+#include "rkdropdown.h"
#include "rkcheckbox.h"
#include "rkpluginspinbox.h"
#include "rkinput.h"
@@ -487,6 +488,8 @@
addConnection (id, "fixed_factors", xml->getStringAttribute (e, "fixed_factors", "#noid#", DL_INFO), "available", false, e);
} else if (e.tagName () == "radio") {
widget = new RKRadio (e, component (), parent_widget);
+ } else if (e.tagName () == "dropdown") {
+ widget = new RKDropDown (e, component (), parent_widget);
} else if (e.tagName () == "checkbox") {
widget = new RKCheckBox (e, component (), parent_widget);
} else if (e.tagName () == "spinbox") {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list