Changeset View
Changeset View
Standalone View
Standalone View
src/formeditor/formIO.cpp
Show First 20 Lines • Show All 269 Lines • ▼ Show 20 Line(s) | |||||
270 | #endif | 270 | #endif | ||
271 | 271 | | |||
272 | QDomDocument domDoc; | 272 | QDomDocument domDoc; | ||
273 | //qDebug() << qPrintable(src); | 273 | //qDebug() << qPrintable(src); | ||
274 | bool parsed = domDoc.setContent(src, false, &errMsg, &errLine, &errCol); | 274 | bool parsed = domDoc.setContent(src, false, &errMsg, &errLine, &errCol); | ||
275 | 275 | | |||
276 | if (!parsed) { | 276 | if (!parsed) { | ||
277 | qWarning() << errMsg; | 277 | qWarning() << errMsg; | ||
278 | qWarning() << "line:" << errLine << "col: " << errCol; | 278 | qWarning() << "line:" << errLine << "col:" << errCol; | ||
279 | return false; | 279 | return false; | ||
280 | } | 280 | } | ||
281 | 281 | | |||
282 | if (!loadFormFromDom(form, container, domDoc)) { | 282 | if (!loadFormFromDom(form, container, domDoc)) { | ||
283 | return false; | 283 | return false; | ||
284 | } | 284 | } | ||
285 | if (preview) { | 285 | if (preview) { | ||
286 | form->setMode(Form::DataMode); | 286 | form->setMode(Form::DataMode); | ||
Show All 19 Lines | 293 | { | |||
306 | } | 306 | } | ||
307 | else { | 307 | else { | ||
308 | _filename = filename; | 308 | _filename = filename; | ||
309 | } | 309 | } | ||
310 | 310 | | |||
311 | QFile file(_filename); | 311 | QFile file(_filename); | ||
312 | if (!file.open(QIODevice::ReadOnly)) { | 312 | if (!file.open(QIODevice::ReadOnly)) { | ||
313 | //! @todo show err msg to the user | 313 | //! @todo show err msg to the user | ||
314 | qWarning() << "Cannot open the file " << _filename; | 314 | qWarning() << "Cannot open the file" << _filename; | ||
315 | return false; | 315 | return false; | ||
316 | } | 316 | } | ||
317 | QDomDocument doc; | 317 | QDomDocument doc; | ||
318 | if (!doc.setContent(&file, false/* !namespaceProcessing*/, | 318 | if (!doc.setContent(&file, false/* !namespaceProcessing*/, | ||
319 | &errMsg, &errLine, &errCol)) { | 319 | &errMsg, &errLine, &errCol)) { | ||
320 | //! @todo show err msg to the user | 320 | //! @todo show err msg to the user | ||
321 | qWarning() << errMsg; | 321 | qWarning() << errMsg; | ||
322 | qWarning() << errLine << "col:" << errCol; | 322 | qWarning() << errLine << "col:" << errCol; | ||
Show All 14 Lines | 330 | { | |||
337 | QDomNamedNodeMap attrs(headerPropertiesEl.attributes()); | 337 | QDomNamedNodeMap attrs(headerPropertiesEl.attributes()); | ||
338 | for(int i = 0; i < attrs.count(); ++i) { | 338 | for(int i = 0; i < attrs.count(); ++i) { | ||
339 | const QDomAttr attr(attrs.item(i).toAttr()); | 339 | const QDomAttr attr(attrs.item(i).toAttr()); | ||
340 | if (!attr.isNull()) { | 340 | if (!attr.isNull()) { | ||
341 | form->headerProperties()->insert(attr.name().toLatin1(), attr.value()); | 341 | form->headerProperties()->insert(attr.name().toLatin1(), attr.value()); | ||
342 | } | 342 | } | ||
343 | } | 343 | } | ||
344 | //update format version information | 344 | //update format version information | ||
345 | QString ver = form->headerProperties()->value("version"); | 345 | const QString ver = form->headerProperties()->value("version"); | ||
346 | qDebug() << "Original format version: " << ver; | 346 | //qDebug() << "Original format version:" << ver; | ||
347 | form->setOriginalFormatVersion(ver); | 347 | form->setOriginalFormatVersion(ver); | ||
348 | bool verOk; | 348 | bool verOk; | ||
349 | const double verNum = ver.toDouble(&verOk); | 349 | const double verNum = ver.toDouble(&verOk); | ||
350 | const double currentVerNum = KFormDesigner::version().toDouble(); | 350 | const double currentVerNum = KFormDesigner::version().toDouble(); | ||
351 | if (verOk) { | 351 | if (verOk) { | ||
352 | if (verNum < currentVerNum) { | 352 | if (verNum < currentVerNum) { | ||
353 | //! @todo We can either 1) convert from old format and later save in a new one or 2) keep old format. | 353 | //! @todo We can either 1) convert from old format and later save in a new one or 2) keep old format. | ||
354 | //! To do this we may need to look at the original format version number. | 354 | //! To do this we may need to look at the original format version number. | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
413 | ///////////// Functions to save/load properties ///////////////////////////// | 413 | ///////////// Functions to save/load properties ///////////////////////////// | ||
414 | ///////////////////////////////////////////////////////////////////////////// | 414 | ///////////////////////////////////////////////////////////////////////////// | ||
415 | 415 | | |||
416 | void | 416 | void | ||
417 | FormIO::savePropertyValue(ObjectTreeItem *item, QDomElement &parentNode, QDomDocument &parent, | 417 | FormIO::savePropertyValue(ObjectTreeItem *item, QDomElement &parentNode, QDomDocument &parent, | ||
418 | const char *name, const QVariant &value) | 418 | const char *name, const QVariant &value) | ||
419 | { | 419 | { | ||
420 | // Widget specific properties and attributes | 420 | // Widget specific properties and attributes | ||
421 | // qDebug() << "Saving the property: " << name; | 421 | // qDebug() << "Saving the property:" << name; | ||
422 | Form *form = item->container() ? item->container()->form() : item->parent()->container()->form(); | 422 | Form *form = item->container() ? item->container()->form() : item->parent()->container()->form(); | ||
423 | WidgetWithSubpropertiesInterface* subpropIface = dynamic_cast<WidgetWithSubpropertiesInterface*>(item->widget()); | 423 | WidgetWithSubpropertiesInterface* subpropIface = dynamic_cast<WidgetWithSubpropertiesInterface*>(item->widget()); | ||
424 | QWidget *subwidget = item->widget(); | 424 | QWidget *subwidget = item->widget(); | ||
425 | bool addSubwidgetFlag = false; | 425 | bool addSubwidgetFlag = false; | ||
426 | int propertyId = item->widget()->metaObject()->indexOfProperty(name); | 426 | int propertyId = item->widget()->metaObject()->indexOfProperty(name); | ||
427 | const bool propertyIsName = qstrcmp(name, "objectName") == 0 || qstrcmp(name, "name") == 0; | 427 | const bool propertyIsName = qstrcmp(name, "objectName") == 0 || qstrcmp(name, "name") == 0; | ||
428 | if (!propertyIsName && propertyId == -1 && subpropIface && subpropIface->subwidget()) { // try property from subwidget | 428 | if (!propertyIsName && propertyId == -1 && subpropIface && subpropIface->subwidget()) { // try property from subwidget | ||
429 | subwidget = subpropIface->subwidget(); | 429 | subwidget = subpropIface->subwidget(); | ||
430 | propertyId = subpropIface->subwidget()->metaObject()->indexOfProperty(name); | 430 | propertyId = subpropIface->subwidget()->metaObject()->indexOfProperty(name); | ||
431 | addSubwidgetFlag = true; | 431 | addSubwidgetFlag = true; | ||
432 | } | 432 | } | ||
433 | if (!propertyIsName && propertyId == -1) { | 433 | if (!propertyIsName && propertyId == -1) { | ||
434 | qDebug() << "The object doesn't have this property. Let's try the WidgetLibrary."; | 434 | //qDebug() << "The object doesn't have this property. Let's try the WidgetLibrary."; | ||
435 | if (form->library()) | 435 | if (form->library()) | ||
436 | form->library()->saveSpecialProperty(item->widget()->metaObject()->className(), name, value, | 436 | form->library()->saveSpecialProperty(item->widget()->metaObject()->className(), name, value, | ||
437 | item->widget(), parentNode, parent); | 437 | item->widget(), parentNode, parent); | ||
438 | return; | 438 | return; | ||
439 | } | 439 | } | ||
440 | 440 | | |||
441 | QMetaProperty meta; | 441 | QMetaProperty meta; | ||
442 | if (!propertyIsName) { | 442 | if (!propertyIsName) { | ||
▲ Show 20 Lines • Show All 778 Lines • ▼ Show 20 Line(s) | 1203 | { | |||
1221 | readChildNodes(form->objectTree(), form->toplevelContainer(), el, container, &buddies); | 1221 | readChildNodes(form->objectTree(), form->toplevelContainer(), el, container, &buddies); | ||
1222 | 1222 | | |||
1223 | // Now the Form is fully loaded, we can assign the buddies | 1223 | // Now the Form is fully loaded, we can assign the buddies | ||
1224 | for (QHash<QString, QLabel*>::ConstIterator it(buddies.constBegin()); | 1224 | for (QHash<QString, QLabel*>::ConstIterator it(buddies.constBegin()); | ||
1225 | it!=buddies.constEnd(); ++it) | 1225 | it!=buddies.constEnd(); ++it) | ||
1226 | { | 1226 | { | ||
1227 | ObjectTreeItem *item = form->objectTree()->lookup(it.key()); | 1227 | ObjectTreeItem *item = form->objectTree()->lookup(it.key()); | ||
1228 | if (!item || !item->widget()) { | 1228 | if (!item || !item->widget()) { | ||
1229 | qDebug() << "Cannot assign buddy for widget " | 1229 | qDebug() << "Cannot assign buddy for widget" | ||
1230 | << it.value()->objectName() << " to " << it.key(); | 1230 | << it.value()->objectName() << "to" << it.key(); | ||
1231 | continue; | 1231 | continue; | ||
1232 | } | 1232 | } | ||
1233 | it.value()->setBuddy(item->widget()); | 1233 | it.value()->setBuddy(item->widget()); | ||
1234 | } | 1234 | } | ||
1235 | form->setInteractiveMode(true); | 1235 | form->setInteractiveMode(true); | ||
1236 | } | 1236 | } | ||
1237 | 1237 | | |||
1238 | void FormIO::readChildNodes(ObjectTreeItem *item, Container *container, const QDomElement &el, | 1238 | void FormIO::readChildNodes(ObjectTreeItem *item, Container *container, const QDomElement &el, | ||
▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines |