From b5a6baa78c1fb008a3a8e03f421a12aa360ef739 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 1 Jun 2016 20:37:51 +0400 Subject: [PATCH] Fix #36 Copy/Paste from within a band --- limereport/lrbanddesignintf.h | 2 +- limereport/lrbasedesignintf.h | 1 + limereport/lrpagedesignintf.cpp | 34 ++++++++++++++++++++++--------- limereport/lrpagedesignintf.h | 2 +- limereport/lrpageitemdesignintf.h | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index be282fa..be7af45 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -208,7 +208,7 @@ public: bool startFromNewPage() const; void setStartFromNewPage(bool startFromNewPage); - + bool canContainChildren(){ return true;} signals: void bandRendered(BandDesignIntf* band); protected: diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index 6d164c1..a3d21c6 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -245,6 +245,7 @@ public: QColor borderColor() const; void setBorderColor(const QColor &borderColor); void setItemVisible(const bool& value); + virtual bool canContainChildren(){ return false;} protected: //ICollectionContainer diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index d35b4fd..7829e1f 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -1202,22 +1202,36 @@ void PageDesignIntf::copy() } } +BaseDesignIntf* PageDesignIntf::findDestObject(BaseDesignIntf* item){ + if (item && item->canContainChildren()) return item; + BaseDesignIntf * curItem = item; + while (curItem && !curItem->canContainChildren()){ + curItem = dynamic_cast(curItem->parentItem()); + } + return curItem; +} + void PageDesignIntf::paste() { QClipboard *clipboard = QApplication::clipboard(); - if (selectedItems().count() == 1) { - BandDesignIntf *band = dynamic_cast(selectedItems().at(0)); - if (band) { - CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), band); + if (!selectedItems().isEmpty()) { + BaseDesignIntf* destItem = findDestObject(dynamic_cast(selectedItems().at(0))); + if (destItem){ + CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), destItem); saveCommand(command); - } else { - PageItemDesignIntf* page = dynamic_cast(selectedItems().at(0)); - if (page){ - CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), page); - saveCommand(command); - } } +// BandDesignIntf *band = dynamic_cast(selectedItems().at(0)); +// if (band) { +// CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), band); +// saveCommand(command); +// } else { +// PageItemDesignIntf* page = dynamic_cast(selectedItems().at(0)); +// if (page){ +// CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), page); +// saveCommand(command); +// } else {} +// } } } diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 1463944..5dd36d4 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -192,7 +192,7 @@ namespace LimeReport { virtual void dropEvent(QGraphicsSceneDragDropEvent *event); LimeReport::BandDesignIntf::BandsType findPriorType(LimeReport::BandDesignIntf::BandsType bandType); - + BaseDesignIntf *findDestObject(BaseDesignIntf *item); bool isExistsObjectName (const QString& objectName, QList &itemsList) const; QRectF getRectByPageSize(PageSize pageSize); diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 0bd5445..8632837 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -111,7 +111,7 @@ public: bool oldPrintMode() const; void setOldPrintMode(bool oldPrintMode); - + bool canContainChildren(){ return true;} protected slots: void bandDeleted(QObject* band); void bandGeometryChanged(QObject* /*object*/, QRectF newGeometry, QRectF oldGeometry);