Development/Tutorials/Kexi/Writing Form Plugin

From KDE TechBase

This will be tutorial about "How to write Kexi 'Form' plugin" for now it is just a bunch of notes and some thoughts about, so if any one would like to start it's own plugin have easier start.

The Place

where to put plugin files:

kexi/plugins/forms/widgets/<plugin dir>

remember about updating CMakeLists.txt

Classes

  1. Factory
  2. Widget

inheritance

For 'Factory' there is only one parent:

  • public KFormDesigner::WidgetFactory

For 'Widget' there is more:

  • public Marble::MarbleWidget,
  • public KFormDesigner::FormWidgetInterface,
  • public KexiFormDataItemInterface

Create Plugin

  • CMakeLists.txt: kde4_add_plugin
  • add export macro to PlugNameFactory.cpp
K_EXPORT_KEXI_FORM_WIDGET_FACTORY_PLUGIN(<factory class name>, <factory name>)

Register

we have to manually register plugin, more info in future...

Implementation details

Some interesting functions.

setValueInternal

void PlugNameWidget::setValueInternal(const QVariant& add, bool removeOld )

This function is used for setting data to widget. One thing that is hard to find: "What value I should set?". Usually you should use m_origValue, this is protected member of KexiFormDataItemInterface and is set in setValue function which then calls our setValueInternal.

Final tips

In my "Map Browser Widget" I needed to get data from two (or three) columns what is currently impossible in Kexi (probably will be possible in next major release). We solve it by serializing all needed data to string and storing it as one column.