0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Parent object changing has been fixed

This commit is contained in:
Arin Alex 2018-04-24 15:51:06 +03:00
parent b9774f62fb
commit 36f75b011b
3 changed files with 29 additions and 6 deletions

View File

@ -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<ComboBoxEditor*>(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<ComboBoxEditor*>(sender())->setTextValue(locationToString(object()->property(propertyName().toLatin1()).toInt()));
}
}

View File

@ -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<ItemDesignIntf*>(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<BaseDesignIntf*>(di);
if (b)
moveItemNode(b, parent);
}
m_defferedItems.clear();
} else {
if (!m_defferedItems.contains(item))
m_defferedItems.append(item);
}
}
void ObjectBrowserNode::setObject(QObject *value)

View File

@ -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<QObject*, ObjectBrowserNode*> m_itemsMap;
bool m_changingItemSelection;
bool m_movingItem;
QList<QObject*> m_defferedItems;
};
} //namespace LimeReport