[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] kexi/formeditor: FormIO: replace static members with local
From:       Jaroslaw Staniek <staniek () kde ! org>
Date:       2014-04-30 21:49:35
Message-ID: E1WfcNj-0004ZI-41 () scm ! kde ! org
[Download RAW message or body]

Git commit 95fa320bc5cb6827b5a1b7e704718505c07683ce by Jaroslaw Staniek.
Committed on 30/04/2014 at 21:38.
Pushed by staniek into branch 'master'.

FormIO: replace static members with local

M  +4    -4    kexi/formeditor/commands.cpp
M  +2    -1    kexi/formeditor/factories/containerfactory.cpp
M  +5    -2    kexi/formeditor/factories/stdwidgetfactory.cpp
M  +35   -19   kexi/formeditor/form.cpp
M  +6    -3    kexi/formeditor/form.h
M  +63   -118  kexi/formeditor/formIO.cpp
M  +10   -20   kexi/formeditor/formIO.h

http://commits.kde.org/calligra/95fa320bc5cb6827b5a1b7e704718505c07683ce

diff --git a/kexi/formeditor/commands.cpp b/kexi/formeditor/commands.cpp
index 467512bf..42fe425 100644
--- a/kexi/formeditor/commands.cpp
+++ b/kexi/formeditor/commands.cpp
@@ -1509,7 +1509,7 @@ void PasteWidgetCommand::execute()
             changePos(el, d->pos);
 
         d->form->setInteractiveMode(false);
-        FormIO::loadWidget(container, el);
+        FormIO::loadWidget(container, el, 0, 0);
         d->form->setInteractiveMode(true);
     }
     else {
@@ -1556,7 +1556,7 @@ void PasteWidgetCommand::execute()
             }
 
             d->form->setInteractiveMode(false);
-            FormIO::loadWidget(container, el);
+            FormIO::loadWidget(container, el, 0, 0);
             d->form->setInteractiveMode(true);
         }
     }
@@ -1795,9 +1795,9 @@ void DeleteWidgetCommand::undo()
         ObjectTreeItem *parent = \
d->form->objectTree()->lookup(d->parents.value(wname));  QDomElement widg = \
n.toElement();  if (parent)
-            FormIO::loadWidget(cont, widg, parent->widget());
+            FormIO::loadWidget(cont, widg, parent->widget(), 0);
         else
-            FormIO::loadWidget(cont, widg);
+            FormIO::loadWidget(cont, widg, 0, 0);
     }
     d->form->setInteractiveMode(true);
 }
diff --git a/kexi/formeditor/factories/containerfactory.cpp \
b/kexi/formeditor/factories/containerfactory.cpp index 48bf5d9..6c81921 100644
--- a/kexi/formeditor/factories/containerfactory.cpp
+++ b/kexi/formeditor/factories/containerfactory.cpp
@@ -820,6 +820,7 @@ bool
 ContainerFactory::readSpecialProperty(const QByteArray &, QDomElement &node, QWidget \
                *w,
                                       KFormDesigner::ObjectTreeItem *item)
 {
+    KFormDesigner::Form *form = item->container() ? item->container()->form() : \
item->parent()->container()->form();  const QString name( node.attribute("name") );
     if ((name == "title") && (item->parent()->widget()->inherits("QTabWidget"))) {
         TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget());
@@ -833,7 +834,7 @@ ContainerFactory::readSpecialProperty(const QByteArray &, \
                QDomElement &node, QWi
             || /*compat*/ KexiUtils::objectIsA(w->parentWidget(), "QWidgetStack")))
     {
         QStackedWidget *stack = dynamic_cast<QStackedWidget*>(w->parentWidget());
-        int index = KFormDesigner::FormIO::readPropertyValue(node.firstChild(), w, \
name).toInt(); +        int index = KFormDesigner::FormIO::readPropertyValue(form, \
node.firstChild(), w, name).toInt();  stack->insertWidget(index, w);
         stack->setCurrentWidget(w);
         item->addModifiedProperty("stackIndex", index);
diff --git a/kexi/formeditor/factories/stdwidgetfactory.cpp \
b/kexi/formeditor/factories/stdwidgetfactory.cpp index d7557f6..8ac301e 100644
--- a/kexi/formeditor/factories/stdwidgetfactory.cpp
+++ b/kexi/formeditor/factories/stdwidgetfactory.cpp
@@ -61,6 +61,7 @@
 #include "form.h"
 #include "widgetlibrary.h"
 #include "stdwidgetfactory.h"
+#include "objecttree.h"
 
 // Some widgets subclass to allow event filtering and some other things
 KexiPictureLabel::KexiPictureLabel(const QPixmap &pix, QWidget *parent)
@@ -863,14 +864,16 @@ StdWidgetFactory::saveListItem(QListWidgetItem *item,
 bool
 StdWidgetFactory::readSpecialProperty(const QByteArray &classname, 
                                       QDomElement &node, QWidget *w, 
-                                      KFormDesigner::ObjectTreeItem *)
+                                      KFormDesigner::ObjectTreeItem *item)
 {
     const QString tag( node.tagName() );
     const QString name( node.attribute("name") );
+    KFormDesigner::Form *form = item->container() ? item->container()->form() : \
item->parent()->container()->form();  
     if ((tag == "item") && (classname == "KComboBox")) {
         KComboBox *combo = dynamic_cast<KComboBox*>(w);
-        QVariant val = \
KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name); +  \
QVariant val = KFormDesigner::FormIO::readPropertyValue( +                    form, \
node.firstChild().firstChild(), w, name);  if (val.canConvert(QVariant::Pixmap))
             combo->addItem(val.value<QPixmap>(), QString());
         else
diff --git a/kexi/formeditor/form.cpp b/kexi/formeditor/form.cpp
index 2d53afc..7b9ae7b 100644
--- a/kexi/formeditor/form.cpp
+++ b/kexi/formeditor/form.cpp
@@ -188,7 +188,7 @@ private:
 class FormPrivate
 {
 public:
-    FormPrivate(Form *form);
+    FormPrivate(Form *form, WidgetLibrary* _library);
     ~FormPrivate();
 
     void enableAction(const char* name, bool enable);
@@ -329,16 +329,21 @@ public:
     QPointer<Container> inlineEditorContainer;
     QByteArray editedWidgetClass;
     QString originalInlineText;
+    bool pixmapsStoredInline;
 
+    WidgetLibrary * const library;
+
+private:
     Form *q;
 };
 }
 
 using namespace KFormDesigner;
 
-FormPrivate::FormPrivate(Form *form)
+FormPrivate::FormPrivate(Form *form, WidgetLibrary* _library)
  : state(Form::WidgetSelecting)
  , internalCollection(static_cast<QObject*>(0))
+ , library(_library)
  , q(form)
 {
     toplevel = 0;
@@ -367,6 +372,7 @@ FormPrivate::FormPrivate(Form *form)
     idOfPropertyCommand = 0;
     selectWidgetEnabled = true;
     executingCommand = 0;
+    pixmapsStoredInline = false;
 }
 
 FormPrivate::~FormPrivate()
@@ -505,16 +511,16 @@ KoProperty::Property::ListData* \
FormPrivate::createValueList(WidgetInfo *winfo,  
 Form::Form(WidgetLibrary* library, Mode mode, KActionCollection &col, ActionGroup& \
group)  : QObject(library)
-        , d( new FormPrivate(this) )
+        , d( new FormPrivate(this, library) )
 {
-    init(library, mode, col, group);
+    init(mode, col, group);
 }
 
 Form::Form(Form *parent)
         : QObject(parent->library())
-        , d( new FormPrivate(this) )
+        , d( new FormPrivate(this, parent->library()) )
 {
-    init(parent->library(), parent->mode(), *parent->actionCollection(), \
*parent->widgetActionGroup()); +    init(parent->mode(), *parent->actionCollection(), \
*parent->widgetActionGroup());  }
 
 Form::~Form()
@@ -523,9 +529,8 @@ Form::~Form()
     delete d;
 }
 
-void Form::init(WidgetLibrary* library, Mode mode, KActionCollection &col, \
KFormDesigner::ActionGroup &group) +void Form::init(Mode mode, KActionCollection \
&col, KFormDesigner::ActionGroup &group)  {
-    m_lib = library;
     d->mode = mode;
     d->features = 0;
     d->widgetActionGroup = &group;
@@ -540,7 +545,7 @@ void Form::init(WidgetLibrary* library, Mode mode, \
KActionCollection &col, KForm  
 WidgetLibrary* Form::library() const
 {
-    return m_lib;
+    return d->library;
 }
 
 KActionCollection  *Form::actionCollection() const
@@ -679,6 +684,16 @@ PixmapCollection* Form::pixmapCollection() const
     return d->pixcollection;
 }
 
+void Form::setPixmapsStoredInline(bool set)
+{
+    d->pixmapsStoredInline = set;
+}
+
+bool Form::pixmapsStoredInline() const
+{
+    return d->pixmapsStoredInline;
+}
+
 ObjectTreeList* Form::tabStops()
 {
     return &(d->tabstops);
@@ -806,7 +821,7 @@ void Form::setMode(Mode mode)
 
     ObjectTreeHash hash(*(d->topTree->hash()));
     foreach (ObjectTreeItem *item, hash) {
-        m_lib->previewWidget(
+        library()->previewWidget(
             item->widget()->metaObject()->className(),
             item->widget(), d->toplevel
         );
@@ -1888,7 +1903,7 @@ bool Form::isPropertyVisible(const QByteArray &property, bool \
isTopLevel,  else
         subwidget = w;
 
-    return m_lib->isPropertyVisible(
+    return library()->isPropertyVisible(
                subwidget->metaObject()->className(), subwidget, property, multiple, \
isTopLevel);  }
 
@@ -1942,7 +1957,7 @@ void Form::createPropertiesForWidget(QWidget *w)
     QHash<QString, QVariant>::ConstIterator modifiedPropertiesIt;
     bool isTopLevel = isTopLevelWidget(w);
     KoProperty::Property *newProp = 0;
-    WidgetInfo *winfo = m_lib->widgetInfoForClassName(w->metaObject()->className());
+    WidgetInfo *winfo = \
library()->widgetInfoForClassName(w->metaObject()->className());  if (!winfo) {
         kWarning() << "no widget info for class" << w->metaObject()->className();
         return;
@@ -1982,7 +1997,7 @@ void Form::createPropertiesForWidget(QWidget *w)
         const char* propertyName = meta.name();
         QWidget *subwidget = subMeta.isValid()//subpropIface
                              ? subpropIface->subwidget() : w;
-        WidgetInfo *subwinfo = m_lib->widgetInfoForClassName(
+        WidgetInfo *subwinfo = library()->widgetInfoForClassName(
                                    subwidget->metaObject()->className());
 //  kDebug() << "$$$ " << subwidget->className();
 
@@ -1996,7 +2011,7 @@ void Form::createPropertiesForWidget(QWidget *w)
             QString desc(d->propCaption.value(meta.name()));
             //! \todo change i18n
             if (desc.isEmpty()) { //try to get property description from factory
-                desc = m_lib->propertyDescForName(subwinfo, propertyName);
+                desc = library()->propertyDescForName(subwinfo, propertyName);
             }
 
             modifiedPropertiesIt = modifiedProperties->find(propertyName);
@@ -2058,7 +2073,7 @@ void Form::createPropertiesForWidget(QWidget *w)
     d->propertySet["objectName"].setAutoSync(false); // name should be updated only \
when pressing Enter  
     if (winfo) {
-        m_lib->setPropertyOptions(d->propertySet, *winfo, w);
+        library()->setPropertyOptions(d->propertySet, *winfo, w);
         d->propertySet.addProperty(newProp = new \
KoProperty::Property("this:classString", winfo->name()));  \
                newProp->setVisible(false);
         d->propertySet.addProperty(newProp = new \
KoProperty::Property("this:iconName", winfo->iconName())); @@ -2767,8 +2782,9 @@ void \
Form::createAlignProperty(const QMetaProperty& meta, QWidget *widget, QWidg  \
i18n("Word Break"), i18n("Word Break"));  d->propertySet.addProperty(p);
         updatePropertyValue(tree, "wordbreak");
-        if (!m_lib->isPropertyVisible(
-                    subwidget->metaObject()->className(), subwidget, p->name(), \
false/*multiple*/, isTopLevel)) { +        if (!library()->isPropertyVisible(
+                subwidget->metaObject()->className(), subwidget, p->name(), \
false/*multiple*/, isTopLevel)) +        {
             p->setVisible(false);
         }
     }
@@ -2989,7 +3005,7 @@ void Form::changeFont()
     QFont font;
     bool oneFontSelected = true;
     foreach (QWidget* widget, *wlist) {
-        if (m_lib->isPropertyVisible(widget->metaObject()->className(), widget, \
"font")) { +        if \
(library()->isPropertyVisible(widget->metaObject()->className(), widget, "font")) {  \
widgetsWithFontProperty.append(widget);  if (oneFontSelected) {
                 if (widgetsWithFontProperty.count() == 1)
@@ -3155,7 +3171,7 @@ bool Form::eventFilter(QObject *obj, QEvent *ev)
         && obj == selectedWidget() && d->inlineEditor)
     {
         // resize widget using resize handles
-        WidgetInfo *winfo = \
m_lib->widgetInfoForClassName(obj->metaObject()->className()); +        WidgetInfo \
*winfo = library()->widgetInfoForClassName(obj->metaObject()->className());  if \
(winfo) {  winfo->factory()->resizeEditor(
                 d->inlineEditor, selectedWidget(), 
diff --git a/kexi/formeditor/form.h b/kexi/formeditor/form.h
index 5f64914..4b0d4ea 100644
--- a/kexi/formeditor/form.h
+++ b/kexi/formeditor/form.h
@@ -114,7 +114,7 @@ public:
     Form(WidgetLibrary* library, Mode mode, KActionCollection &col, ActionGroup& \
group);  
     /*! Creates Form object as a child of other form. */
-    Form(Form *parent);
+    explicit Form(Form *parent);
 
     ~Form();
 
@@ -247,6 +247,10 @@ public:
 
     PixmapCollection* pixmapCollection() const;
 
+    void setPixmapsStoredInline(bool set);
+
+    bool pixmapsStoredInline() const;
+
     //! Options for addCommand() method.
     enum AddCommandOption {
         DontExecuteCommand = 0, //!< command is not executed in addCommand()
@@ -753,11 +757,10 @@ protected:
     virtual bool eventFilter(QObject *obj, QEvent *ev);
 
 private:
-    void init(WidgetLibrary* library, Mode mode, KActionCollection &col, \
KFormDesigner::ActionGroup &group); +    void init(Mode mode, KActionCollection &col, \
KFormDesigner::ActionGroup &group);  
     void selectWidgetInternal(QWidget *w, WidgetSelectionFlags flags);
 
-    WidgetLibrary *m_lib;
     FormPrivate * const d;
 
     friend class FormWidget;
diff --git a/kexi/formeditor/formIO.cpp b/kexi/formeditor/formIO.cpp
index 90506d4..f83f242 100644
--- a/kexi/formeditor/formIO.cpp
+++ b/kexi/formeditor/formIO.cpp
@@ -30,7 +30,6 @@
 #include <QLayout>
 #include <QObject>
 #include <QDateTime>
-#include <QLabel>
 #include <QPainter>
 #include <QPaintEvent>
 #include <QVBoxLayout>
@@ -110,11 +109,6 @@ CustomWidget::paintEvent(QPaintEvent *)
 
 using namespace KFormDesigner;
 
-QHash<QString, QLabel*> *FormIO::m_buddies = 0;
-ObjectTreeItem *FormIO::m_currentItem = 0;
-Form *FormIO::m_currentForm = 0;
-bool FormIO::m_savePixmapsInline = false;
-
 // FormIO itself
 
 KFORMEDITOR_EXPORT uint KFormDesigner::version()
@@ -193,8 +187,6 @@ FormIO::saveFormToString(Form *form, QString &dest, int indent)
 bool
 FormIO::saveFormToDom(Form *form, QDomDocument &domDoc)
 {
-    m_currentForm = form;
-
     domDoc = QDomDocument("UI");
     QDomElement uiElement = domDoc.createElement("UI");
     domDoc.appendChild(uiElement);
@@ -259,9 +251,6 @@ FormIO::saveFormToDom(Form *form, QDomDocument &domDoc)
 #endif
 
     form->setUndoStackClean();
-
-    m_currentForm = 0;
-    m_currentItem = 0;
     return true;
 }
 
@@ -360,8 +349,6 @@ FormIO::loadFormFromFile(Form *form, QWidget *container, const \
QString &filename  bool
 FormIO::loadFormFromDom(Form *form, QWidget *container, QDomDocument &inBuf)
 {
-    m_currentForm = form;
-
     QDomElement ui = inBuf.firstChildElement("UI");
 
     //custom properties
@@ -396,12 +383,9 @@ FormIO::loadFormFromDom(Form *form, QWidget *container, \
QDomDocument &inBuf)  }
 
     // Load the pixmap collection
-    m_savePixmapsInline = ((ui.firstChildElement("pixmapinproject").isNull()) || \
                (!ui.firstChildElement("images").isNull()));
-#ifdef __GNUC__
-#warning pixmapcollection
-#else
-#pragma WARNING( pixmapcollection )
-#endif
+    form->setPixmapsStoredInline(ui.firstChildElement("pixmapinproject").isNull()
+                                 || !ui.firstChildElement("images").isNull());
+//! @todo pixmapcollection
 #ifndef KEXI_NO_PIXMAPCOLLECTION
     form->pixmapCollection()->load(ui.namedItem("collection"));
 #endif
@@ -439,10 +423,6 @@ FormIO::loadFormFromDom(Form *form, QWidget *container, \
QDomDocument &inBuf)  // Load the form connections
     form->connectionBuffer()->load(ui.namedItem("connections"));
 #endif
-
-    m_currentForm = 0;
-    m_currentItem = 0;
-
     return true;
 }
 
@@ -451,15 +431,16 @@ FormIO::loadFormFromDom(Form *form, QWidget *container, \
QDomDocument &inBuf)  \
/////////////////////////////////////////////////////////////////////////////  
 void
-FormIO::savePropertyValue(QDomElement &parentNode, QDomDocument &parent, const char \
                *name,
-                          const QVariant &value, QWidget *w, WidgetLibrary *lib)
+FormIO::savePropertyValue(ObjectTreeItem *item, QDomElement &parentNode, \
QDomDocument &parent, +                          const char *name, const QVariant \
&value)  {
-    // Widget specific properties and attributes ///////////////
+    // Widget specific properties and attributes
 // kDebug() << "Saving the property: " << name;
-    WidgetWithSubpropertiesInterface* subpropIface = \
                dynamic_cast<WidgetWithSubpropertiesInterface*>(w);
-    QWidget *subwidget = w;
+    Form *form = item->container() ? item->container()->form() : \
item->parent()->container()->form(); +    WidgetWithSubpropertiesInterface* \
subpropIface = dynamic_cast<WidgetWithSubpropertiesInterface*>(item->widget()); +    \
QWidget *subwidget = item->widget();  bool addSubwidgetFlag = false;
-    int propertyId = w->metaObject()->indexOfProperty(name);
+    int propertyId = item->widget()->metaObject()->indexOfProperty(name);
     const bool propertyIsName = qstrcmp(name, "objectName") == 0 || qstrcmp(name, \
                "name") == 0;
     if (!propertyIsName && propertyId == -1 && subpropIface && \
subpropIface->subwidget()) { // try property from subwidget  subwidget = \
subpropIface->subwidget(); @@ -468,8 +449,9 @@ FormIO::savePropertyValue(QDomElement \
&parentNode, QDomDocument &parent, const c  }
     if (!propertyIsName && propertyId == -1) {
         kDebug() << "The object doesn't have this property. Let's try the \
                WidgetLibrary.";
-        if (lib)
-            lib->saveSpecialProperty(w->metaObject()->className(), name, value, w, \
parentNode, parent); +        if (form->library())
+            form->library()->saveSpecialProperty(item->widget()->metaObject()->className(), \
name, value, +                                                 item->widget(), \
parentNode, parent);  return;
     }
 
@@ -513,11 +495,11 @@ FormIO::savePropertyValue(QDomElement &parentNode, QDomDocument \
&parent, const c  QDomText valueE;
         QDomElement type = parent.createElement("pixmap");
         QByteArray property = propertyE.attribute("name").toLatin1();
-//todo  QCString pixmapName = \
                m_currentItem->widget()->property("pixmapName").toCString();
-        if (m_savePixmapsInline /* (js)too risky: || \
m_currentItem->pixmapName(property).isNull() */) +//! @todo  QCString pixmapName = \
m_currentItem->widget()->property("pixmapName").toCString(); +        if \
(form->pixmapsStoredInline() /* (js)too risky: || \
                m_currentItem->pixmapName(property).isNull() */)
             valueE = parent.createTextNode(saveImage(parent, \
value.value<QPixmap>()));  else
-            valueE = parent.createTextNode(m_currentItem->pixmapName(property));
+            valueE = parent.createTextNode(item->pixmapName(property));
         type.appendChild(valueE);
         propertyE.appendChild(type);
         parentNode.appendChild(propertyE);
@@ -781,8 +763,7 @@ FormIO::savePropertyElement(QDomElement &parentNode, QDomDocument \
&domDoc, const  parentNode.appendChild(propertyE);
 }
 
-QVariant
-FormIO::readPropertyValue(QDomNode node, QObject *obj, const QString &name)
+QVariant FormIO::readPropertyValue(Form *form, QDomNode node, QObject *obj, const \
QString &name)  {
     QDomElement tag = node.toElement();
     QString text = tag.text();
@@ -884,18 +865,16 @@ FormIO::readPropertyValue(QDomNode node, QObject *obj, const \
QString &name)  s.setVerticalStretch(vs.text().toInt());
         return s;
     } else if (type == "pixmap") {
-#ifdef __GNUC__
-#warning pixmapcollection
-#else
-#pragma WARNING( pixmapcollection )
-#endif
+//! @todo pixmapcollection
 #ifndef KEXI_NO_PIXMAPCOLLECTION
-        if (m_savePixmapsInline || !m_currentForm || !m_currentItem || \
!m_currentForm->pixmapCollection()->contains(text)) +        if \
(form->pixmapsStoredInline() || !m_currentForm || !m_currentItem || \
!m_currentForm->pixmapCollection()->contains(text))  return \
loadImage(tag.ownerDocument(), text);  else {
             m_currentItem->setPixmapName(name.toLatin1(), text);
-            return m_currentForm->pixmapCollection()->getPixmap(text);
+            return form->pixmapCollection()->getPixmap(text);
         }
+#else
+        Q_UNUSED(form);
 #endif
         return QPixmap();
     }
@@ -940,15 +919,8 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, \
QDomDocument &domD  return;
     }
 #endif
-    bool resetCurrentForm = false;
-    m_currentItem = item;
-    if (!m_currentForm) { // copying widget
-        resetCurrentForm = true;
-        m_currentForm = item->container() ? item->container()->form() : \
                item->parent()->container()->form();
-    }
-
-
-    WidgetLibrary *lib = m_currentForm->library();
+    Form *form = item->container() ? item->container()->form() : \
item->parent()->container()->form(); +    WidgetLibrary *lib = form->library();
 
     // We create the "widget" element
     QDomElement tclass = domDoc.createElement("widget");
@@ -977,7 +949,7 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, \
QDomDocument &domD  // We save every property in the modifProp list of the \
ObjectTreeItem  QHash<QString, QVariant> hash(*(item->modifiedProperties()));
     QStringList names(hash.keys());
-    savePropertyValue(tclass, domDoc, "objectName", item->widget()->objectName(), \
item->widget()); +    savePropertyValue(item, tclass, domDoc, "objectName", \
item->widget()->objectName());  names.removeOne("objectName");
 
     // Important: save dataSource property FIRST before properties like "alignment"
@@ -990,13 +962,12 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, \
                QDomDocument &domD
     // We don't want to save the geometry if the widget is inside a layout (so \
parent.tagName() == "grid" for example)  if (item && !item->parent()) {
         // save form widget size, but not its position
-        savePropertyValue(tclass, domDoc, "geometry",
-                          QRect(QPoint(0, 0), item->widget()->size()),
-                          item->widget());
+        savePropertyValue(item, tclass, domDoc, "geometry",
+                          QRect(QPoint(0, 0), item->widget()->size()));
     }
     // normal widget (if == "UI', it means we're copying widget)
     else if (parent.tagName() == "widget" || parent.tagName() == "UI")
-        savePropertyValue(tclass, domDoc, "geometry", \
item->widget()->property("geometry"), item->widget()); +        \
savePropertyValue(item, tclass, domDoc, "geometry", \
item->widget()->property("geometry"));  
     names.removeOne("geometry");
     names.removeOne("layout");
@@ -1029,16 +1000,15 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, \
QDomDocument &domD  if (names.contains(name)) {
             names.removeOne(name);
             savePropertyValue(
-                tclass, domDoc, "alignment", 
-                item->widget()->property("alignment"), item->widget());
+                item, tclass, domDoc, "alignment",
+                item->widget()->property("alignment"));
             break;
         }
     }
 
     foreach (const QString& name, names) {
-        savePropertyValue(tclass, domDoc, name.toLatin1(),
-                          item->widget()->property(name.toLatin1()),
-                          item->widget(), lib);
+        savePropertyValue(item, tclass, domDoc, name.toLatin1(),
+                          item->widget()->property(name.toLatin1()));
     }
     hash.clear();
 
@@ -1055,7 +1025,7 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, \
                QDomDocument &domD
     if (item->container() && item->container()->layoutType() != Form::NoLayout) {
         if (item->container()->layout()) { // there is a layout
             layout = domDoc.createElement("temp");
-            savePropertyValue(layout, domDoc, "objectName", "unnamed", \
item->widget()); +            savePropertyValue(item, layout, domDoc, "objectName", \
"unnamed");  if (item->modifiedProperties()->contains("layoutMargin"))
                 savePropertyElement(layout, domDoc, "property", "margin", \
item->container()->layoutMargin());  if \
(item->modifiedProperties()->contains("layoutSpacing")) @@ -1143,10 +1113,6 @@ \
FormIO::saveWidget(ObjectTreeItem *item, QDomElement &parent, QDomDocument &domD  
     addIncludeFileName(lib->includeFileName(
                            item->widget()->metaObject()->className()), domDoc);
-
-    if (resetCurrentForm)
-        m_currentForm = 0;
-    m_currentItem = 0;
 }
 
 void
@@ -1162,14 +1128,10 @@ FormIO::cleanClipboard(QDomElement &uiElement)
         uiElement.insertAfter(uiElement.firstChildElement("images"), QDomNode());
 }
 
-void
-FormIO::loadWidget(Container *container, const QDomElement &el, QWidget *parent)
+void FormIO::loadWidget(Container *container, const QDomElement &el, QWidget \
*parent, +                        QHash<QString, QLabel*> *buddies)
 {
-    bool resetCurrentForm = false;
-    if (!m_currentForm) { // pasting widget
-        resetCurrentForm = true;
-        m_currentForm = container->form();
-    }
+    Form *form = container->form();
 
     // We first look for the widget's name
     QString wname;
@@ -1247,7 +1209,7 @@ FormIO::loadWidget(Container *container, const QDomElement &el, \
QWidget *parent)  if (!w)
         return;
 //! @todo allow setting this for data view mode as well
-    if (m_currentForm->mode() == Form::DesignMode) {
+    if (form->mode() == Form::DesignMode) {
         //don't generate accelerators for widgets in design mode
         KAcceleratorManager::setNoAccel(w);
     }
@@ -1277,7 +1239,6 @@ FormIO::loadWidget(Container *container, const QDomElement &el, \
                QWidget *parent)
         dynamic_cast<DesignTimeDynamicChildWidgetHandler*>(w)->assignItem(item);
     }
 
-    m_currentItem = item;
     // if we are inside a Grid, we need to insert the widget in the good cell
     if (container->layoutType() == Form::Grid)  {
         QGridLayout *layout = (QGridLayout*)container->layout();
@@ -1300,7 +1261,7 @@ FormIO::loadWidget(Container *container, const QDomElement &el, \
QWidget *parent)  } else if (container->layout())
         container->layout()->addWidget(w);
 
-    readChildNodes(item, container, el, w);
+    readChildNodes(item, container, el, w, buddies);
 
     if (item->container() && item->container()->layout())
         item->container()->layout()->activate();
@@ -1323,10 +1284,6 @@ FormIO::loadWidget(Container *container, const QDomElement \
                &el, QWidget *parent)
         // Sanity: force fill background if there's color but not 'fill background' \
set  w->setAutoFillBackground(true);
     }
-
-    if (resetCurrentForm)
-        m_currentForm = 0;
-    m_currentItem = 0;
 }
 
 void
@@ -1341,7 +1298,6 @@ FormIO::createToplevelWidget(Form *form, QWidget *container, \
QDomElement &el)  wname = n.toElement().text();
             break;
         }
-
     }
     // And rename the widget and its ObjectTreeItem
     container->setObjectName(wname);
@@ -1349,17 +1305,12 @@ FormIO::createToplevelWidget(Form *form, QWidget *container, \
QDomElement &el)  form->objectTree()->rename(form->objectTree()->name(), wname);
     form->setInteractiveMode(false);
 
-    QHash<QString, QLabel*> *oldBuddies = 0;
-    if (m_buddies) // save old buddies (for subforms)
-        oldBuddies = m_buddies;
-    m_buddies = new QHash<QString, QLabel*>();
-    m_currentItem = form->objectTree();
-
-    readChildNodes(form->objectTree(), form->toplevelContainer(), el, container);
+    QHash<QString, QLabel*> buddies;
+    readChildNodes(form->objectTree(), form->toplevelContainer(), el, container, \
&buddies);  
     // Now the Form is fully loaded, we can assign the buddies
-    for (QHash<QString, QLabel*>::ConstIterator it(m_buddies->constBegin());
-        it!=m_buddies->constEnd(); ++it)
+    for (QHash<QString, QLabel*>::ConstIterator it(buddies.constBegin());
+        it!=buddies.constEnd(); ++it)
     {
         ObjectTreeItem *item = form->objectTree()->lookup(it.key());
         if (!item || !item->widget()) {
@@ -1369,16 +1320,11 @@ FormIO::createToplevelWidget(Form *form, QWidget *container, \
QDomElement &el)  }
         it.value()->setBuddy(item->widget());
     }
-    delete m_buddies;
-    m_buddies = oldBuddies; // and restore it
-
-    m_currentItem = 0;
-
     form->setInteractiveMode(true);
 }
 
-void
-FormIO::readChildNodes(ObjectTreeItem *item, Container *container, const QDomElement \
&el, QWidget *w) +void FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomElement &el, +                       QWidget *w, QHash<QString, \
QLabel*> *buddies)  {
     QString eltag = el.tagName();
 
@@ -1405,8 +1351,9 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  if (node.attribute("subwidget") == "true") {
                 //this is property for subwidget: remember it for delayed setting
                 //because now the subwidget could be not created yet (true e.g. for \
                KexiDBAutoField)
-                item->addSubproperty(name.toLatin1(), \
                readPropertyValue(node.firstChild(), w, name));
-                const QVariant val(readPropertyValue(node.firstChild(), w, name));
+                item->addSubproperty(name.toLatin1(),
+                                     readPropertyValue(container->form(), \
node.firstChild(), w, name)); +                const QVariant \
val(readPropertyValue(container->form(), node.firstChild(), w, name));  kDebug() << \
val.toStringList();  item->addSubproperty(name.toLatin1(), val);
                 //subwidget->setProperty(name.toLatin1(), val);
@@ -1416,7 +1363,11 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  
             // We cannot assign the buddy now as the buddy widget may not be created \
yet  if (name == "buddy") {
-                m_buddies->insert(readPropertyValue(node.firstChild(), w, \
name).toString(), (QLabel*)w); +                if (buddies && \
qobject_cast<QLabel*>(w)) { +                    buddies->insert(readPropertyValue(
+                                    container->form(), node.firstChild(), w, \
name).toString(), +                                    qobject_cast<QLabel*>(w));
+                }
             }
             else if (    (eltag == "grid" || eltag == "hbox" || eltag == "vbox")
                       && item->container()
@@ -1424,23 +1375,17 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  {
                 // We load the margin of a Layout
                 if (name == "margin")  {
-                    int margin = readPropertyValue(node.firstChild(), w, \
name).toInt(); +                    int margin = readPropertyValue(container->form(), \
node.firstChild(), w, name).toInt();  item->container()->setLayoutMargin(margin);
                     item->container()->layout()->setMargin(margin);
                 }
                 // We load the spacing of a Layout
                 else if (name == "spacing")  {
-                    int spacing = readPropertyValue(node.firstChild(), w, \
name).toInt(); +                    int spacing = \
readPropertyValue(container->form(), node.firstChild(), w, name).toInt();  \
item->container()->setLayoutSpacing(spacing);  \
item->container()->layout()->setSpacing(spacing);  } else if ((name == "justify")) {
-#ifdef KEXI_NO_FLOWLAYOUT
-#ifdef __GNUC__
-#warning Port Kexi flow layout!
-#else
-#pragma WARNING( Port Kexi flow layout! )
-#endif
-#else
+#ifndef KEXI_NO_FLOWLAYOUT
                     bool justify = readPropertyValue(node.firstChild(), w, \
                name).toBool();
                     KexiFlowLayout *flow = \
static_cast<KexiFlowLayout*>(item->container()->layout());  if (flow)
@@ -1450,7 +1395,7 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  }
             else if (name == "paletteBackgroundColor" || name == \
"paletteForegroundColor") {  QPalette widgetPalette(w->palette());
-                QVariant val(readPropertyValue(node.firstChild(), w, name));
+                QVariant val(readPropertyValue(container->form(), node.firstChild(), \
w, name));  if (!val.isNull())
                     widgetPalette.setColor(
                         name == "paletteBackgroundColor" ? w->backgroundRole() : \
w->foregroundRole(), @@ -1474,7 +1419,7 @@ FormIO::readChildNodes(ObjectTreeItem \
*item, Container *container, const QDomEle  }
             }
             else { // we have a normal property, let's load it
-                QVariant val(readPropertyValue(node.firstChild(), w, name));
+                QVariant val(readPropertyValue(container->form(), node.firstChild(), \
w, name));  if (name == "geometry" && dynamic_cast<FormWidget*>(w)) {
                     //fix geometry if needed - this is top level form widget
                     QRect r(val.toRect());
@@ -1502,12 +1447,12 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  }
         else if (tag == "widget") { // a child widget
             if (item->container()) // we are a Container
-                loadWidget(item->container(), node);
+                loadWidget(item->container(), node, 0, buddies);
             else
-                loadWidget(container, node, w);
+                loadWidget(container, node, w, buddies);
         }
         else if (tag == "spacer")  {
-            loadWidget(container, node, w);
+            loadWidget(container, node, w, buddies);
         }
         else if (tag == "grid") {
             // first, see if it is flow layout
@@ -1550,17 +1495,17 @@ FormIO::readChildNodes(ObjectTreeItem *item, Container \
*container, const QDomEle  QGridLayout *layout = new QGridLayout(item->widget());
                 item->container()->setLayout((QLayout*)layout);
             }
-            readChildNodes(item, container, node, w);
+            readChildNodes(item, container, node, w, buddies);
         } else if (tag == "vbox")  {
             item->container()->setLayoutType(Form::VBox);
             QVBoxLayout *layout = new QVBoxLayout(item->widget());
             item->container()->setLayout((QLayout*)layout);
-            readChildNodes(item, container, node, w);
+            readChildNodes(item, container, node, w, buddies);
         } else if (tag == "hbox") {
             item->container()->setLayoutType(Form::HBox);
             QHBoxLayout *layout = new QHBoxLayout(item->widget());
             item->container()->setLayout((QLayout*)layout);
-            readChildNodes(item, container, node, w);
+            readChildNodes(item, container, node, w, buddies);
         } else {// unknown tag, we let the Factory handle it
             if (w->metaObject()->className() == QString::fromLatin1("CustomWidget"))
                 item->storeUnknownProperty(node);
diff --git a/kexi/formeditor/formIO.h b/kexi/formeditor/formIO.h
index e5e8731..c934a1b 100644
--- a/kexi/formeditor/formIO.h
+++ b/kexi/formeditor/formIO.h
@@ -25,6 +25,7 @@
 #include <QPixmap>
 #include <QLabel>
 #include <QPaintEvent>
+#include <QLabel>
 
 #include <kexi_export.h>
 
@@ -146,8 +147,8 @@ public:
         If parent = 0, the Container::widget() is used as parent widget.
         This is used to copy/paste widgets.
     */
-    static void loadWidget(Container *container,
-                           const QDomElement &el, QWidget *parent = 0);
+    static void loadWidget(Container *container, const QDomElement &el,
+                           QWidget *parent, QHash<QString, QLabel*> *buddies);
 
     /*! Save an element in the \a domDoc as child of \a parentNode.
       The element will be saved like this :
@@ -162,20 +163,20 @@ public:
        \param obj    the widget whose property is being read
        \param name   the name of the property being read
     */
-    static QVariant readPropertyValue(QDomNode node, QObject *obj, const QString \
&name); +    static QVariant readPropertyValue(Form *form, QDomNode node, QObject \
*obj, const QString &name);  
     /*! Write an object property in the DOM doc.
+       \param item   the widget item whose property is being saved
        \param parentNode the DOM document to write to
        \param name   the name of the property being saved
        \param value  the value of this property
-       \param w      the widget whose property is being saved
-       \param lib    the widget library for which the property is being saved
 
        Properties of subwidget are saved with subwidget="true" arribute added
        to 'property' XML element.
     */
-    static void savePropertyValue(QDomElement &parentNode, QDomDocument &parent, \
                const char *name,
-                                  const QVariant &value, QWidget *w, WidgetLibrary \
*lib = 0); +    static void savePropertyValue(ObjectTreeItem *item, QDomElement \
&parentNode, +                                  QDomDocument &parent, const char \
*name, +                                  const QVariant &value);
 
 protected:
     /*! Saves the QVariant \a value as text to be included in an xml file, with \a \
parentNode.*/ @@ -202,7 +203,8 @@ protected:
 
     /*! Reads the child nodes of a "widget" element. */
     static void readChildNodes(ObjectTreeItem *tree, Container *container,
-                               const QDomElement &el, QWidget *w);
+                               const QDomElement &el, QWidget *w,
+                               QHash<QString, QLabel*> *buddies);
 
     /*! Adds an include file name to be saved in the "includehints" part of .ui \
file,  which is needed by uic. */
@@ -211,18 +213,6 @@ protected:
 private:
     // This hash stores buddies associations until the Form is completely loaded.
     static QHash<QString, QLabel*> *m_buddies;
-
-    /// Instead of having to pass these for every functions, we just store them in \
                the class
-    //static QWidgdet  *m_currentWidget;
-//! @todo remove
-#ifdef __GNUC__
-#warning "remove m_currentItem and m_currentForm.."
-#else
-#pragma WARNING( remove m_currentItem and m_currentForm.. )
-#endif
-    static ObjectTreeItem   *m_currentItem;
-    static Form *m_currentForm;
-    static bool m_savePixmapsInline;
 };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic