From 36f75b011b895f1c3629872c439a4baccb85b5d0 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Tue, 24 Apr 2018 15:51:06 +0300 Subject: [PATCH] Parent object changing has been fixed --- limereport/items/lrsubitemparentpropitem.cpp | 3 +- limereport/objectsbrowser/lrobjectbrowser.cpp | 29 ++++++++++++++++--- limereport/objectsbrowser/lrobjectbrowser.h | 3 ++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/limereport/items/lrsubitemparentpropitem.cpp b/limereport/items/lrsubitemparentpropitem.cpp index 1587bc9..b02cfa7 100644 --- a/limereport/items/lrsubitemparentpropitem.cpp +++ b/limereport/items/lrsubitemparentpropitem.cpp @@ -77,8 +77,8 @@ void LimeReport::ItemLocationPropItem::setPropertyEditorData(QWidget *propertyEd } void LimeReport::ItemLocationPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index){ - object()->setProperty(propertyName().toLatin1(),stringToLocation(qobject_cast(propertyEditor)->text())); model->setData(index,object()->property(propertyName().toLatin1())); + setValueToObject(propertyName(), propertyValue()); } QString LimeReport::ItemLocationPropItem::locationToString(LimeReport::ItemDesignIntf::LocationType location) const{ @@ -92,6 +92,5 @@ LimeReport::ItemDesignIntf::LocationType LimeReport::ItemLocationPropItem::strin void LimeReport::ItemLocationPropItem::slotLocationChanged(const QString &text){ if ( locationToString(object()->property(propertyName().toLatin1()).toInt())!=text){ object()->setProperty(propertyName().toLatin1(),stringToLocation(text)); - dynamic_cast(sender())->setTextValue(locationToString(object()->property(propertyName().toLatin1()).toInt())); } } diff --git a/limereport/objectsbrowser/lrobjectbrowser.cpp b/limereport/objectsbrowser/lrobjectbrowser.cpp index e657a81..a5ee464 100644 --- a/limereport/objectsbrowser/lrobjectbrowser.cpp +++ b/limereport/objectsbrowser/lrobjectbrowser.cpp @@ -35,7 +35,8 @@ namespace LimeReport{ ObjectBrowser::ObjectBrowser(QWidget *parent) - :QWidget(parent), m_report(NULL), m_mainWindow(NULL), m_changingItemSelection(false) + :QWidget(parent), m_report(NULL), m_mainWindow(NULL), + m_changingItemSelection(false), m_movingItem(false) { QVBoxLayout *layout = new QVBoxLayout(this); setLayout(layout); @@ -86,6 +87,7 @@ void ObjectBrowser::slotClear() } void ObjectBrowser::fillNode(QTreeWidgetItem* parentNode, BaseDesignIntf* reportItem, BaseDesignIntf *ignoredItem){ + foreach (BaseDesignIntf* item, reportItem->childBaseItems()) { if (item != ignoredItem){ ObjectBrowserNode* treeItem = new ObjectBrowserNode(parentNode); @@ -93,11 +95,11 @@ void ObjectBrowser::fillNode(QTreeWidgetItem* parentNode, BaseDesignIntf* report treeItem->setObject(item); treeItem->setIcon(0,QIcon(":/items/"+extractClassName(item->metaObject()->className()))); connect(item, SIGNAL(propertyObjectNameChanged(QString,QString)), - this, SLOT(slotPropertyObjectNameChanged(QString,QString))); + this, SLOT(slotPropertyObjectNameChanged(QString,QString)), Qt::UniqueConnection); ItemDesignIntf* i = dynamic_cast(item); if (i){ connect(i, SIGNAL(itemLocationChanged(BaseDesignIntf*,BaseDesignIntf*)), - this, SLOT(slotItemParentChanged(BaseDesignIntf*,BaseDesignIntf*))); + this, SLOT(slotItemParentChanged(BaseDesignIntf*,BaseDesignIntf*)), Qt::UniqueConnection); } m_itemsMap.insert(item,treeItem); parentNode->addChild(treeItem); @@ -283,7 +285,9 @@ void ObjectBrowser::slotActivePageUpdated(LimeReport::PageDesignIntf *) buildTree(); } -void ObjectBrowser::slotItemParentChanged(BaseDesignIntf* item, BaseDesignIntf* parent) + + +void ObjectBrowser::moveItemNode(BaseDesignIntf* item, BaseDesignIntf* parent) { if (m_itemsMap.contains(item) && m_itemsMap.contains(parent)){ m_itemsMap.value(item)->parent()->removeChild(m_itemsMap.value(item)); @@ -293,7 +297,24 @@ void ObjectBrowser::slotItemParentChanged(BaseDesignIntf* item, BaseDesignIntf* item->setSelected(true); m_changingItemSelection = false; } +} +void ObjectBrowser::slotItemParentChanged(BaseDesignIntf* item, BaseDesignIntf* parent) +{ + if (!m_movingItem){ + m_movingItem = true; + moveItemNode(item, parent); + m_movingItem = false; + foreach(QObject* di, m_defferedItems){ + BaseDesignIntf* b = dynamic_cast(di); + if (b) + moveItemNode(b, parent); + } + m_defferedItems.clear(); + } else { + if (!m_defferedItems.contains(item)) + m_defferedItems.append(item); + } } void ObjectBrowserNode::setObject(QObject *value) diff --git a/limereport/objectsbrowser/lrobjectbrowser.h b/limereport/objectsbrowser/lrobjectbrowser.h index 4bdcb52..9d9482b 100644 --- a/limereport/objectsbrowser/lrobjectbrowser.h +++ b/limereport/objectsbrowser/lrobjectbrowser.h @@ -60,6 +60,7 @@ protected: void buildTree(BaseDesignIntf *ignoredItem = 0); void removeItem(BaseDesignIntf* item); void findAndRemove(QTreeWidgetItem *node, BaseDesignIntf *item); + void moveItemNode(BaseDesignIntf* item, BaseDesignIntf* parent); private slots: // void slotObjectNameChanged(const QString& objectName); void slotPropertyObjectNameChanged(const QString& oldName, const QString& newName); @@ -82,6 +83,8 @@ private: QTreeWidget* m_treeView; QMap m_itemsMap; bool m_changingItemSelection; + bool m_movingItem; + QList m_defferedItems; }; } //namespace LimeReport