[Kst] branches/work/kst/portto4/kst/src
Mike Fenton
mike at staikos.net
Mon Jun 2 17:19:21 CEST 2008
SVN commit 815796 by fenton:
Add Dialog Default support for DatObject Plugins.
Fully document SamplePlugin to serve as guide for DataObjectPlugin creation.
M +1 -0 libkstapp/application.cpp
M +3 -0 libkstapp/basicplugindialog.cpp
M +3 -0 libkstapp/basicplugindialog.h
M +10 -18 libkstmath/dataobject.cpp
M +2 -5 libkstmath/dataobject.h
M +1 -1 libkstmath/dataobjectplugin.h
M +108 -5 plugins/sampleplugin/sampleplugin.cpp
M +1 -1 plugins/sampleplugin/sampleplugin.h
--- branches/work/kst/portto4/kst/src/libkstapp/application.cpp #815795:815796
@@ -41,6 +41,7 @@
//inside of libkst... no?
QSettings *settingsObject = new QSettings("kstdatarc", QSettings::IniFormat);
DataSource::setupOnStartup(settingsObject);
+ DataObject::setupOnStartup(settingsObject);
_mainWindow = new MainWindow;
--- branches/work/kst/portto4/kst/src/libkstapp/basicplugindialog.cpp #815795:815796
@@ -56,6 +56,8 @@
if (dataObject) {
_basicPluginTab->configWidget()->setupFromObject(dataObject);
+ } else {
+ _basicPluginTab->configWidget()->load();
}
}
@@ -71,6 +73,7 @@
ObjectPtr BasicPluginDialog::createNewDataObject() const {
DataObjectPtr dataObject = DataObject::createPlugin(_pluginName, _document->objectStore(), _basicPluginTab->configWidget());
+ _basicPluginTab->configWidget()->save();
return dataObject;
}
--- branches/work/kst/portto4/kst/src/libkstapp/basicplugindialog.h #815795:815796
@@ -31,6 +31,9 @@
DataObjectConfigWidget* configWidget() { return _configWidget; }
+ void loadSettings();
+ void saveSettings();
+
private:
DataObjectConfigWidget* _configWidget;
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.cpp #815795:815796
@@ -42,6 +42,13 @@
namespace Kst {
+static QSettings *settingsObject = 0L;
+static QMap<QString,QString> urlMap;
+void DataObject::setupOnStartup(QSettings *cfg) {
+ settingsObject = cfg;
+}
+
+
DataObject::DataObject(ObjectStore *store) : Object() {
_curveHints = new CurveHintList;
_isInputLoaded = false;
@@ -135,7 +142,7 @@
for (DataObjectPluginList::ConstIterator it = _pluginList.begin(); it != _pluginList.end(); ++it) {
if ((*it)->pluginName() == name) {
if ((*it)->hasConfigWidget()) {
- return (*it)->configWidget();
+ return (*it)->configWidget(settingsObject);
}
break;
}
@@ -807,8 +814,8 @@
/////////////////////////////////////////////////////////////////////////////
-DataObjectConfigWidget::DataObjectConfigWidget()
-: QWidget(0L), _cfg(0L) {
+DataObjectConfigWidget::DataObjectConfigWidget(QSettings *cfg)
+: QWidget(0L), _cfg(_cfg) {
}
@@ -824,21 +831,6 @@
}
-void DataObjectConfigWidget::setConfig(QSettings *cfg) {
- _cfg = cfg;
-}
-
-
-void DataObjectConfigWidget::setInstance(DataObjectPtr inst) {
- _instance = inst;
-}
-
-
-DataObjectPtr DataObjectConfigWidget::instance() const {
- return _instance;
-}
-
-
void DataObjectConfigWidget::setObjectStore(ObjectStore* store) {
Q_UNUSED(store);
}
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.h #815795:815796
@@ -52,6 +52,7 @@
virtual void attach();
// These static methods are not for plugins to use
+ static void setupOnStartup(QSettings*);
static void cleanupForExit();
/** Returns a list of object plugins found on the system. */
static QStringList pluginList();
@@ -186,10 +187,9 @@
Q_OBJECT
friend class DataObject;
public:
- DataObjectConfigWidget(); // will be reparented later
+ DataObjectConfigWidget(QSettings*); // will be reparented later
virtual ~DataObjectConfigWidget();
- virtual void setConfig(QSettings*);
virtual void setupFromObject(Object* dataObject);
virtual void setupSlots(QWidget* dialog);
@@ -206,9 +206,6 @@
protected:
QSettings *_cfg;
- // If _instance is nonzero, then your settings are to be saved for this
- // particular instance of the source, as opposed to globally.
- DataObjectPtr _instance;
} KST_EXPORT;
}
--- branches/work/kst/portto4/kst/src/libkstmath/dataobjectplugin.h #815795:815796
@@ -29,7 +29,7 @@
virtual DataObject *create(ObjectStore *store, DataObjectConfigWidget *configWidget, bool setupInputsOutputs = true) const = 0;
- virtual DataObjectConfigWidget *configWidget() const = 0;
+ virtual DataObjectConfigWidget *configWidget(QSettings *settingsObject) const = 0;
};
--- branches/work/kst/portto4/kst/src/plugins/sampleplugin/sampleplugin.cpp #815795:815796
@@ -21,33 +21,58 @@
static const QString& SCALAR_OUT = "Scalar Out";
static const QString& STRING_OUT = "String Out";
+/**********************
+ConfigWidgetSamplePlugin - This class defines the config widget that will be added to the
+BasicPluginDialog container for configuring the plugin. By default the BasicPluginDialog has
+no controls and thus all desired inputs/outputs/options should included in the .ui.
+DataObjectConfigWidget is defined in dataobject.h
+***********************/
class ConfigWidgetSamplePlugin : public Kst::DataObjectConfigWidget, public Ui_SamplePluginConfig {
public:
- ConfigWidgetSamplePlugin() : DataObjectConfigWidget(), Ui_SamplePluginConfig() {
+ ConfigWidgetSamplePlugin(QSettings* cfg) : DataObjectConfigWidget(cfg), Ui_SamplePluginConfig() {
setupUi(this);
}
~ConfigWidgetSamplePlugin() {}
- void setObjectStore(Kst::ObjectStore* store) { _vector->setObjectStore(store); }
+ void setObjectStore(Kst::ObjectStore* store) {
+ // _store must be set here. Any additional controls requiring the objectstore should also
+ // have it set at this time.
+ _store = store;
+ _vector->setObjectStore(store);
+ }
void setupSlots(QWidget* dialog) {
if (dialog) {
+ // In order to for Apply button logic to function. All controls change state must be linked to
+ // the dialog's modified signal.
connect(_vector, SIGNAL(selectionChanged(QString)), dialog, SIGNAL(modified()));
}
}
+ // All information in the config widget must be publically accessible so that the plugin can pull
+ // the required information and use it construct the object.
Kst::VectorPtr selectedVector() { return _vector->selectedVector(); };
void setSelectedVector(Kst::VectorPtr vector) { return _vector->setSelectedVector(vector); };
+ // This function is required and is used when editing of the object is triggered. It must be able
+ // to configure the widget with the settings currently in use by the object.
virtual void setupFromObject(Kst::Object* dataObject) {
if (SamplePluginSource* source = static_cast<SamplePluginSource*>(dataObject)) {
setSelectedVector(source->vector());
}
}
+ // This function is used when loading a .kst file from disk. The plugins are expected to store any
+ // required parameters as attributes of the plugin tag. The name and type are handled by BasicPluginFactory
+ // as are all inputs and outputs. This should be used for any non-generic attributes associated with the plugin.
+ // If false is returned, the creation of the object will not occur.
+ // NOTE: Saving of the object is done in the objects saveProperties function. Values must match between them.
virtual bool configurePropertiesFromXml(Kst::ObjectStore *store, QXmlStreamAttributes& attrs) {
+ Q_UNUSED(store);
+ Q_UNUSED(attrs);
+
bool validTag = true;
// QStringRef av;
@@ -58,9 +83,47 @@
return validTag;
}
+
+ public slots:
+ // Dialog Defaults control - Save
+ // Uses the provided QSettings Object to save the plugin default details as a new group.
+ // Called everytime a new dialog request is made. Does not affect editing.
+ virtual void save() {
+ if (_cfg) {
+ _cfg->beginGroup("Sample DataObject Plugin");
+ _cfg->setValue("Input Vector", _vector->selectedVector()->Name());
+ _cfg->endGroup();
+ }
+ }
+
+ // Dialog Defaults control - Load
+ // Uses the provided QSettings Object to load the plugin default details.
+ // Called everytime a new dialog request is completed. Does not get called on edit.
+ virtual void load() {
+ if (_cfg && _store) {
+ _cfg->beginGroup("Sample DataObject Plugin");
+ QString vectorName = _cfg->value("Input Vector").toString();
+ Kst::Object* object = _store->retrieveObject(vectorName);
+ Kst::Vector* vector = static_cast<Kst::Vector*>(object);
+ if (vector) {
+ setSelectedVector(vector);
+ }
+ _cfg->endGroup();
+ }
+ }
+
+ private:
+ Kst::ObjectStore *_store;
+
};
+/**********************
+SamplePluginSource - This class defines the main DataObject which derives from BasicPlugin (a DataObject).
+The key functions that this class must provide is the ability to create/modify the object, setup outputs, and
+be able to process the data (algorithm function).
+
+***********************/
SamplePluginSource::SamplePluginSource(Kst::ObjectStore *store)
: Kst::BasicPlugin(store) {
}
@@ -75,6 +138,8 @@
}
+// Change is used to configure the DataObject and will be run immediately after initial creation as well as
+// when modifications have occured.
void SamplePluginSource::change(Kst::DataObjectConfigWidget *configWidget) {
if (ConfigWidgetSamplePlugin* config = static_cast<ConfigWidgetSamplePlugin*>(configWidget)) {
setInputVector(VECTOR_IN, config->selectedVector());
@@ -87,15 +152,23 @@
}
+// The algorithm function must handle all the data calculations for the plugin. This function is run during
+// each update of the input objects which includes after creation of the object. Only output objects that have
+// have setOutputVector/setOutputScalar/setOutputString should be updated as others will not appear outside of
+// the plugin.
bool SamplePluginSource::algorithm() {
Kst::VectorPtr inputVector = _inputVectors[VECTOR_IN];
Kst::VectorPtr outputVector = _outputVectors[VECTOR_OUT];
outputVector->resize(inputVector->length(), false);
+ // Sample only. Copy all values from input vector to output vector.
for (int i = 0; i < inputVector->length(); i++) {
outputVector->value()[i] = inputVector->value(i);
}
+
+ // Return true to continue update. Returning false indicates that the update did not result in the output
+ // objects changing and will not trigger updates of objects using them.
return true;
}
@@ -135,26 +208,54 @@
}
+// This function allows for support of saving / loading this object from a .kst file. The function should only
+// write attributes as any other advancement of the StreamWriter will result in a malformed Xml document. All
+// values required to recreate the should be saved here. All Input/Output Objects are saved by BasicPlugin and do
+// not need to be stored here. This should be used for any non-generic attributes associated with the plugin.
+// NOTE: Loading of the object is done in the configWidgets configurePropertiesFromXml function. Values must match between them.
void SamplePluginSource::saveProperties(QXmlStreamWriter &s) {
-// s.writeAttribute("tag", tag().tagString());
+ Q_UNUSED(s);
+// s.writeAttribute("value", _configValue);
}
+// Name used to identify the plugin. Used when loading the plugin.
QString SamplePlugin::pluginName() const { return "Sample DataObject Plugin"; }
+
+/**********************
+SamplePlugin - This class defines the plugin interface to the DataObject defined by the plugin.
+The primary requirements of this class are to provide the necessary connections to create the object
+which includes providing access to the configuration widget.
+
+***********************/
+
+// The create function is responsible for creating the DataObject. It is provided the ObjectStore as well as a
+// fully configured configWidget to setup the object from.
+// setupInputOutputs is a flag to mark whether the object should automatically setup the inputs and outputs. New
+// creations will always configure them. When loading from a .kst file they will be done manually.
Kst::DataObject *SamplePlugin::create(Kst::ObjectStore *store, Kst::DataObjectConfigWidget *configWidget, bool setupInputsOutputs) const {
if (ConfigWidgetSamplePlugin* config = static_cast<ConfigWidgetSamplePlugin*>(configWidget)) {
+ // Create a generic object.
SamplePluginSource* object = store->createObject<SamplePluginSource>();
+ // Setup the object values based on the config widget.
+ // object->setValue(config->value());
+
+ // If the inputs/outputs should be configured, setup them up from the configWidget.
if (setupInputsOutputs) {
object->setInputVector(VECTOR_IN, config->selectedVector());
object->setupOutputs();
}
+ // Set the pluginName.
object->setPluginName(pluginName());
+ // Trigger an update of the object. This is required to trigger the algorithm call and creation of the output.
+ // If inputs/outputs was not triggered, this will also be run a second time after all inputs/outputs have been
+ // configured.
object->writeLock();
object->update();
object->unlock();
@@ -165,8 +266,10 @@
}
-Kst::DataObjectConfigWidget *SamplePlugin::configWidget() const {
- return new ConfigWidgetSamplePlugin();
+// Request for this plugins configuration widget.
+Kst::DataObjectConfigWidget *SamplePlugin::configWidget(QSettings *settingsObject) const {
+ ConfigWidgetSamplePlugin *widget = new ConfigWidgetSamplePlugin(settingsObject);
+ return widget;
}
Q_EXPORT_PLUGIN2(kstplugin_sampleplugin, SamplePlugin)
--- branches/work/kst/portto4/kst/src/plugins/sampleplugin/sampleplugin.h #815795:815796
@@ -57,7 +57,7 @@
virtual Kst::DataObject *create(Kst::ObjectStore *store, Kst::DataObjectConfigWidget *configWidget, bool setupInputsOutputs = true) const;
- virtual Kst::DataObjectConfigWidget *configWidget() const;
+ virtual Kst::DataObjectConfigWidget *configWidget(QSettings *settingsObject) const;
};
#endif
More information about the Kst
mailing list