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 =3D d->form->objectTree()->lookup(d->parent= s.value(wname)); QDomElement widg =3D 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/formedit= or/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 &nod= e, QWidget *w, KFormDesigner::ObjectTreeItem *item) { + KFormDesigner::Form *form =3D item->container() ? item->container()->f= orm() : item->parent()->container()->form(); const QString name( node.attribute("name") ); if ((name =3D=3D "title") && (item->parent()->widget()->inherits("QTab= Widget"))) { TabWidgetBase *tab =3D dynamic_cast(w->parentWidge= t()); @@ -833,7 +834,7 @@ ContainerFactory::readSpecialProperty(const QByteArray = &, QDomElement &node, QWi || /*compat*/ KexiUtils::objectIsA(w->parentWidget(), "QWidget= Stack"))) { QStackedWidget *stack =3D dynamic_cast(w->parentW= idget()); - int index =3D KFormDesigner::FormIO::readPropertyValue(node.firstC= hild(), w, name).toInt(); + int index =3D 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/formedit= or/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 =3D item->container() ? item->container()->f= orm() : item->parent()->container()->form(); = if ((tag =3D=3D "item") && (classname =3D=3D "KComboBox")) { KComboBox *combo =3D dynamic_cast(w); - QVariant val =3D KFormDesigner::FormIO::readPropertyValue(node.fir= stChild().firstChild(), w, name); + QVariant val =3D KFormDesigner::FormIO::readPropertyValue( + form, node.firstChild().firstChild(), w, name); if (val.canConvert(QVariant::Pixmap)) combo->addItem(val.value(), 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 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(0)) + , library(_library) , q(form) { toplevel =3D 0; @@ -367,6 +372,7 @@ FormPrivate::FormPrivate(Form *form) idOfPropertyCommand =3D 0; selectWidgetEnabled =3D true; executingCommand =3D 0; + pixmapsStoredInline =3D false; } = FormPrivate::~FormPrivate() @@ -505,16 +511,16 @@ KoProperty::Property::ListData* FormPrivate::createVa= lueList(WidgetInfo *winfo, = Form::Form(WidgetLibrary* library, Mode mode, KActionCollection &col, Acti= onGroup& 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->widgetActio= nGroup()); } = 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::ActionGr= oup &group) { - m_lib =3D library; d->mode =3D mode; d->features =3D 0; d->widgetActionGroup =3D &group; @@ -540,7 +545,7 @@ void Form::init(WidgetLibrary* library, Mode mode, KAct= ionCollection &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 =3D 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 &proper= ty, bool isTopLevel, else subwidget =3D 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::ConstIterator modifiedPropertiesIt; bool isTopLevel =3D isTopLevelWidget(w); KoProperty::Property *newProp =3D 0; - WidgetInfo *winfo =3D m_lib->widgetInfoForClassName(w->metaObject()->c= lassName()); + WidgetInfo *winfo =3D library()->widgetInfoForClassName(w->metaObject(= )->className()); if (!winfo) { kWarning() << "no widget info for class" << w->metaObject()->class= Name(); return; @@ -1982,7 +1997,7 @@ void Form::createPropertiesForWidget(QWidget *w) const char* propertyName =3D meta.name(); QWidget *subwidget =3D subMeta.isValid()//subpropIface ? subpropIface->subwidget() : w; - WidgetInfo *subwinfo =3D m_lib->widgetInfoForClassName( + WidgetInfo *subwinfo =3D 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 f= actory - desc =3D m_lib->propertyDescForName(subwinfo, propertyName= ); + desc =3D library()->propertyDescForName(subwinfo, property= Name); } = modifiedPropertiesIt =3D modifiedProperties->find(propertyName= ); @@ -2058,7 +2073,7 @@ void Form::createPropertiesForWidget(QWidget *w) d->propertySet["objectName"].setAutoSync(false); // name should be upd= ated only when pressing Enter = if (winfo) { - m_lib->setPropertyOptions(d->propertySet, *winfo, w); + library()->setPropertyOptions(d->propertySet, *winfo, w); d->propertySet.addProperty(newProp =3D new KoProperty::Property("t= his:classString", winfo->name())); newProp->setVisible(false); d->propertySet.addProperty(newProp =3D new KoProperty::Property("t= his:iconName", winfo->iconName())); @@ -2767,8 +2782,9 @@ void Form::createAlignProperty(const QMetaProperty& m= eta, 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->na= me(), 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 =3D true; foreach (QWidget* widget, *wlist) { - if (m_lib->isPropertyVisible(widget->metaObject()->className(), wi= dget, "font")) { + if (library()->isPropertyVisible(widget->metaObject()->className()= , widget, "font")) { widgetsWithFontProperty.append(widget); if (oneFontSelected) { if (widgetsWithFontProperty.count() =3D=3D 1) @@ -3155,7 +3171,7 @@ bool Form::eventFilter(QObject *obj, QEvent *ev) && obj =3D=3D selectedWidget() && d->inlineEditor) { // resize widget using resize handles - WidgetInfo *winfo =3D m_lib->widgetInfoForClassName(obj->metaObjec= t()->className()); + WidgetInfo *winfo =3D library()->widgetInfoForClassName(obj->metaO= bject()->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, Action= Group& 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 =3D 0, //!< command is not executed in addComma= nd() @@ -753,11 +757,10 @@ protected: virtual bool eventFilter(QObject *obj, QEvent *ev); = private: - void init(WidgetLibrary* library, Mode mode, KActionCollection &col, K= FormDesigner::ActionGroup &group); + void init(Mode mode, KActionCollection &col, KFormDesigner::ActionGrou= p &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 #include #include -#include #include #include #include @@ -110,11 +109,6 @@ CustomWidget::paintEvent(QPaintEvent *) = using namespace KFormDesigner; = -QHash *FormIO::m_buddies =3D 0; -ObjectTreeItem *FormIO::m_currentItem =3D 0; -Form *FormIO::m_currentForm =3D 0; -bool FormIO::m_savePixmapsInline =3D 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 =3D form; - domDoc =3D QDomDocument("UI"); QDomElement uiElement =3D domDoc.createElement("UI"); domDoc.appendChild(uiElement); @@ -259,9 +251,6 @@ FormIO::saveFormToDom(Form *form, QDomDocument &domDoc) #endif = form->setUndoStackClean(); - - m_currentForm =3D 0; - m_currentItem =3D 0; return true; } = @@ -360,8 +349,6 @@ FormIO::loadFormFromFile(Form *form, QWidget *container= , const QString &filename bool FormIO::loadFormFromDom(Form *form, QWidget *container, QDomDocument &inBu= f) { - m_currentForm =3D form; - QDomElement ui =3D inBuf.firstChildElement("UI"); = //custom properties @@ -396,12 +383,9 @@ FormIO::loadFormFromDom(Form *form, QWidget *container= , QDomDocument &inBuf) } = // Load the pixmap collection - m_savePixmapsInline =3D ((ui.firstChildElement("pixmapinproject").isNu= ll()) || (!ui.firstChildElement("images").isNull())); -#ifdef __GNUC__ -#warning pixmapcollection -#else -#pragma WARNING( pixmapcollection ) -#endif + form->setPixmapsStoredInline(ui.firstChildElement("pixmapinproject").i= sNull() + || !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 =3D 0; - m_currentItem =3D 0; - return true; } = @@ -451,15 +431,16 @@ FormIO::loadFormFromDom(Form *form, QWidget *containe= r, QDomDocument &inBuf) //////////////////////////////////////////////////////////////////////////= /// = void -FormIO::savePropertyValue(QDomElement &parentNode, QDomDocument &parent, c= onst char *name, - const QVariant &value, QWidget *w, WidgetLibrary= *lib) +FormIO::savePropertyValue(ObjectTreeItem *item, QDomElement &parentNode, Q= DomDocument &parent, + const char *name, const QVariant &value) { - // Widget specific properties and attributes /////////////// + // Widget specific properties and attributes // kDebug() << "Saving the property: " << name; - WidgetWithSubpropertiesInterface* subpropIface =3D dynamic_cast(w); - QWidget *subwidget =3D w; + Form *form =3D item->container() ? item->container()->form() : item->p= arent()->container()->form(); + WidgetWithSubpropertiesInterface* subpropIface =3D dynamic_cast(item->widget()); + QWidget *subwidget =3D item->widget(); bool addSubwidgetFlag =3D false; - int propertyId =3D w->metaObject()->indexOfProperty(name); + int propertyId =3D item->widget()->metaObject()->indexOfProperty(name); const bool propertyIsName =3D qstrcmp(name, "objectName") =3D=3D 0 || = qstrcmp(name, "name") =3D=3D 0; if (!propertyIsName && propertyId =3D=3D -1 && subpropIface && subprop= Iface->subwidget()) { // try property from subwidget subwidget =3D subpropIface->subwidget(); @@ -468,8 +449,9 @@ FormIO::savePropertyValue(QDomElement &parentNode, QDom= Document &parent, const c } if (!propertyIsName && propertyId =3D=3D -1) { kDebug() << "The object doesn't have this property. Let's try the = WidgetLibrary."; - if (lib) - lib->saveSpecialProperty(w->metaObject()->className(), name, v= alue, w, parentNode, parent); + if (form->library()) + form->library()->saveSpecialProperty(item->widget()->metaObjec= t()->className(), name, value, + item->widget(), parentNod= e, parent); return; } = @@ -513,11 +495,11 @@ FormIO::savePropertyValue(QDomElement &parentNode, QD= omDocument &parent, const c QDomText valueE; QDomElement type =3D parent.createElement("pixmap"); QByteArray property =3D propertyE.attribute("name").toLatin1(); -//todo QCString pixmapName =3D m_currentItem->widget()->property("pixmapN= ame").toCString(); - if (m_savePixmapsInline /* (js)too risky: || m_currentItem->pixmap= Name(property).isNull() */) +//! @todo QCString pixmapName =3D m_currentItem->widget()->property("pixm= apName").toCString(); + if (form->pixmapsStoredInline() /* (js)too risky: || m_currentItem= ->pixmapName(property).isNull() */) valueE =3D parent.createTextNode(saveImage(parent, value.value= ())); else - valueE =3D parent.createTextNode(m_currentItem->pixmapName(pro= perty)); + valueE =3D parent.createTextNode(item->pixmapName(property)); type.appendChild(valueE); propertyE.appendChild(type); parentNode.appendChild(propertyE); @@ -781,8 +763,7 @@ FormIO::savePropertyElement(QDomElement &parentNode, QD= omDocument &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 =3D node.toElement(); QString text =3D 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 =3D=3D "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_currentIte= m || !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 =3D false; - m_currentItem =3D item; - if (!m_currentForm) { // copying widget - resetCurrentForm =3D true; - m_currentForm =3D item->container() ? item->container()->form() : = item->parent()->container()->form(); - } - - - WidgetLibrary *lib =3D m_currentForm->library(); + Form *form =3D item->container() ? item->container()->form() : item->p= arent()->container()->form(); + WidgetLibrary *lib =3D form->library(); = // We create the "widget" element QDomElement tclass =3D domDoc.createElement("widget"); @@ -977,7 +949,7 @@ FormIO::saveWidget(ObjectTreeItem *item, QDomElement &p= arent, QDomDocument &domD // We save every property in the modifProp list of the ObjectTreeItem QHash hash(*(item->modifiedProperties())); QStringList names(hash.keys()); - savePropertyValue(tclass, domDoc, "objectName", item->widget()->object= Name(), item->widget()); + savePropertyValue(item, tclass, domDoc, "objectName", item->widget()->= objectName()); names.removeOne("objectName"); = // Important: save dataSource property FIRST before properties like "a= lignment" @@ -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() =3D=3D "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 =3D=3D "UI', it means we're copying widget) else if (parent.tagName() =3D=3D "widget" || parent.tagName() =3D=3D "= UI") - savePropertyValue(tclass, domDoc, "geometry", item->widget()->prop= erty("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, QDomElemen= t &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() !=3D Form::No= Layout) { if (item->container()->layout()) { // there is a layout layout =3D domDoc.createElement("temp"); - savePropertyValue(layout, domDoc, "objectName", "unnamed", ite= m->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()), dom= Doc); - - if (resetCurrentForm) - m_currentForm =3D 0; - m_currentItem =3D 0; } = void @@ -1162,14 +1128,10 @@ FormIO::cleanClipboard(QDomElement &uiElement) uiElement.insertAfter(uiElement.firstChildElement("images"), QDomN= ode()); } = -void -FormIO::loadWidget(Container *container, const QDomElement &el, QWidget *p= arent) +void FormIO::loadWidget(Container *container, const QDomElement &el, QWidg= et *parent, + QHash *buddies) { - bool resetCurrentForm =3D false; - if (!m_currentForm) { // pasting widget - resetCurrentForm =3D true; - m_currentForm =3D container->form(); - } + Form *form =3D container->form(); = // We first look for the widget's name QString wname; @@ -1247,7 +1209,7 @@ FormIO::loadWidget(Container *container, const QDomEl= ement &el, QWidget *parent) if (!w) return; //! @todo allow setting this for data view mode as well - if (m_currentForm->mode() =3D=3D Form::DesignMode) { + if (form->mode() =3D=3D Form::DesignMode) { //don't generate accelerators for widgets in design mode KAcceleratorManager::setNoAccel(w); } @@ -1277,7 +1239,6 @@ FormIO::loadWidget(Container *container, const QDomEl= ement &el, QWidget *parent) dynamic_cast(w)->assignItem(= item); } = - m_currentItem =3D item; // if we are inside a Grid, we need to insert the widget in the good c= ell if (container->layoutType() =3D=3D Form::Grid) { QGridLayout *layout =3D (QGridLayout*)container->layout(); @@ -1300,7 +1261,7 @@ FormIO::loadWidget(Container *container, const QDomEl= ement &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 QDomE= lement &el, QWidget *parent) // Sanity: force fill background if there's color but not 'fill ba= ckground' set w->setAutoFillBackground(true); } - - if (resetCurrentForm) - m_currentForm =3D 0; - m_currentItem =3D 0; } = void @@ -1341,7 +1298,6 @@ FormIO::createToplevelWidget(Form *form, QWidget *con= tainer, QDomElement &el) wname =3D n.toElement().text(); break; } - } // And rename the widget and its ObjectTreeItem container->setObjectName(wname); @@ -1349,17 +1305,12 @@ FormIO::createToplevelWidget(Form *form, QWidget *c= ontainer, QDomElement &el) form->objectTree()->rename(form->objectTree()->name(), wname); form->setInteractiveMode(false); = - QHash *oldBuddies =3D 0; - if (m_buddies) // save old buddies (for subforms) - oldBuddies =3D m_buddies; - m_buddies =3D new QHash(); - m_currentItem =3D form->objectTree(); - - readChildNodes(form->objectTree(), form->toplevelContainer(), el, cont= ainer); + QHash buddies; + readChildNodes(form->objectTree(), form->toplevelContainer(), el, cont= ainer, &buddies); = // Now the Form is fully loaded, we can assign the buddies - for (QHash::ConstIterator it(m_buddies->constBegin()= ); - it!=3Dm_buddies->constEnd(); ++it) + for (QHash::ConstIterator it(buddies.constBegin()); + it!=3Dbuddies.constEnd(); ++it) { ObjectTreeItem *item =3D form->objectTree()->lookup(it.key()); if (!item || !item->widget()) { @@ -1369,16 +1320,11 @@ FormIO::createToplevelWidget(Form *form, QWidget *c= ontainer, QDomElement &el) } it.value()->setBuddy(item->widget()); } - delete m_buddies; - m_buddies =3D oldBuddies; // and restore it - - m_currentItem =3D 0; - form->setInteractiveMode(true); } = -void -FormIO::readChildNodes(ObjectTreeItem *item, Container *container, const Q= DomElement &el, QWidget *w) +void FormIO::readChildNodes(ObjectTreeItem *item, Container *container, co= nst QDomElement &el, + QWidget *w, QHash *buddies) { QString eltag =3D el.tagName(); = @@ -1405,8 +1351,9 @@ FormIO::readChildNodes(ObjectTreeItem *item, Containe= r *container, const QDomEle if (node.attribute("subwidget") =3D=3D "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(no= de.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(), no= de.firstChild(), w, name)); kDebug() << val.toStringList(); item->addSubproperty(name.toLatin1(), val); //subwidget->setProperty(name.toLatin1(), val); @@ -1416,7 +1363,11 @@ FormIO::readChildNodes(ObjectTreeItem *item, Contain= er *container, const QDomEle = // We cannot assign the buddy now as the buddy widget may not = be created yet if (name =3D=3D "buddy") { - m_buddies->insert(readPropertyValue(node.firstChild(), w, = name).toString(), (QLabel*)w); + if (buddies && qobject_cast(w)) { + buddies->insert(readPropertyValue( + container->form(), node.firstChild(), = w, name).toString(), + qobject_cast(w)); + } } else if ( (eltag =3D=3D "grid" || eltag =3D=3D "hbox" || el= tag =3D=3D "vbox") && item->container() @@ -1424,23 +1375,17 @@ FormIO::readChildNodes(ObjectTreeItem *item, Contai= ner *container, const QDomEle { // We load the margin of a Layout if (name =3D=3D "margin") { - int margin =3D readPropertyValue(node.firstChild(), w,= name).toInt(); + int margin =3D readPropertyValue(container->form(), no= de.firstChild(), w, name).toInt(); item->container()->setLayoutMargin(margin); item->container()->layout()->setMargin(margin); } // We load the spacing of a Layout else if (name =3D=3D "spacing") { - int spacing =3D readPropertyValue(node.firstChild(), w= , name).toInt(); + int spacing =3D readPropertyValue(container->form(), n= ode.firstChild(), w, name).toInt(); item->container()->setLayoutSpacing(spacing); item->container()->layout()->setSpacing(spacing); } else if ((name =3D=3D "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 =3D readPropertyValue(node.firstChild(), = w, name).toBool(); KexiFlowLayout *flow =3D static_cast(= item->container()->layout()); if (flow) @@ -1450,7 +1395,7 @@ FormIO::readChildNodes(ObjectTreeItem *item, Containe= r *container, const QDomEle } else if (name =3D=3D "paletteBackgroundColor" || name =3D=3D "= paletteForegroundColor") { QPalette widgetPalette(w->palette()); - QVariant val(readPropertyValue(node.firstChild(), w, name)= ); + QVariant val(readPropertyValue(container->form(), node.fir= stChild(), w, name)); if (!val.isNull()) widgetPalette.setColor( name =3D=3D "paletteBackgroundColor" ? w->backgrou= ndRole() : w->foregroundRole(), @@ -1474,7 +1419,7 @@ FormIO::readChildNodes(ObjectTreeItem *item, Containe= r *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.fir= stChild(), w, name)); if (name =3D=3D "geometry" && dynamic_cast(w)= ) { //fix geometry if needed - this is top level form widg= et QRect r(val.toRect()); @@ -1502,12 +1447,12 @@ FormIO::readChildNodes(ObjectTreeItem *item, Contai= ner *container, const QDomEle } else if (tag =3D=3D "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 =3D=3D "spacer") { - loadWidget(container, node, w); + loadWidget(container, node, w, buddies); } else if (tag =3D=3D "grid") { // first, see if it is flow layout @@ -1550,17 +1495,17 @@ FormIO::readChildNodes(ObjectTreeItem *item, Contai= ner *container, const QDomEle QGridLayout *layout =3D new QGridLayout(item->widget()); item->container()->setLayout((QLayout*)layout); } - readChildNodes(item, container, node, w); + readChildNodes(item, container, node, w, buddies); } else if (tag =3D=3D "vbox") { item->container()->setLayoutType(Form::VBox); QVBoxLayout *layout =3D new QVBoxLayout(item->widget()); item->container()->setLayout((QLayout*)layout); - readChildNodes(item, container, node, w); + readChildNodes(item, container, node, w, buddies); } else if (tag =3D=3D "hbox") { item->container()->setLayoutType(Form::HBox); QHBoxLayout *layout =3D 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() =3D=3D QString::fromLatin1("C= ustomWidget")) 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 #include #include +#include = #include = @@ -146,8 +147,8 @@ public: If parent =3D 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 =3D 0); + static void loadWidget(Container *container, const QDomElement &el, + QWidget *parent, QHash *buddi= es); = /*! 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 Q= String &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 sa= ved = Properties of subwidget are saved with subwidget=3D"true" arribute = added to 'property' XML element. */ - static void savePropertyValue(QDomElement &parentNode, QDomDocument &p= arent, const char *name, - const QVariant &value, QWidget *w, Widge= tLibrary *lib =3D 0); + static void savePropertyValue(ObjectTreeItem *item, QDomElement &paren= tNode, + 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 *buddies); = /*! Adds an include file name to be saved in the "includehints" part o= f .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 *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; }; = }