From 6641215cc0940163348bc7acc0587940443bc712 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 13 Jul 2018 17:40:49 +0300 Subject: [PATCH] Bands relocation redo, undo fixed --- common.pri | 2 +- limereport/lrpagedesignintf.cpp | 45 +++++++++++++++++++---- limereport/lrpagedesignintf.h | 10 ++++++ limereport/lrpageitemdesignintf.cpp | 55 ++++++++++++++++------------- limereport/lrpageitemdesignintf.h | 3 +- 5 files changed, 82 insertions(+), 33 deletions(-) diff --git a/common.pri b/common.pri index dd2e624..5163922 100644 --- a/common.pri +++ b/common.pri @@ -62,7 +62,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 89 +LIMEREPORT_VERSION_RELEASE = 90 LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"' DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\" diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 67d8408..e0f1747 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -870,10 +870,17 @@ void PageDesignIntf::saveSelectedItemsGeometry() void PageDesignIntf::checkSizeOrPosChanges() { - CommandIf::Ptr posCommand; if ((selectedItems().count() > 0) && (m_positionStamp.count() > 0)) { - if (m_positionStamp[0].pos != selectedItems().at(0)->pos()) { + bool bandFound = false; + foreach(QGraphicsItem* item, selectedItems()){ + BandDesignIntf* band = dynamic_cast(item); + if (band){ + bandFound = true; + break; + } + } + if (!bandFound && (m_positionStamp[0].pos != selectedItems().at(0)->pos())) { posCommand = createChangePosCommand(); } m_positionStamp.clear(); @@ -909,16 +916,14 @@ CommandIf::Ptr PageDesignIntf::createChangePosCommand() QVector newPoses; foreach(ReportItemPos itemPos, m_positionStamp) { BaseDesignIntf *reportItem = reportItemByName(itemPos.objectName); - if (reportItem) { ReportItemPos newPos; newPos.objectName = reportItem->objectName(); newPos.pos = reportItem->pos(); newPoses.append(newPos); } - } + } return PosChangedCommand::create(this, m_positionStamp, newPoses); - } CommandIf::Ptr PageDesignIntf::createChangeSizeCommand() @@ -2240,7 +2245,35 @@ qreal ItemProjections::square(QRectF rect) qreal ItemProjections::square(BaseDesignIntf *item) { - return square(QRectF(item->pos().x(),item->pos().y(),item->width(),item->height())); + return square(QRectF(item->pos().x(),item->pos().y(),item->width(),item->height())); +} + +CommandIf::Ptr BandSwapCommand::create(PageDesignIntf *page, const QString &bandName, const QString &bandToSwapName) +{ + BandSwapCommand *command = new BandSwapCommand(); + command->setPage(page); + command->bandName = bandName; + command->bandToSwapName = bandToSwapName; + return CommandIf::Ptr(command); +} + +bool BandSwapCommand::doIt() +{ + BandDesignIntf* band = dynamic_cast(page()->reportItemByName(bandName)); + BandDesignIntf* bandToSwap = dynamic_cast(page()->reportItemByName(bandToSwapName)); + if (band && bandToSwap){ + page()->pageItem()->swapBands(band, bandToSwap); + return true; + } + return false; +} + +void BandSwapCommand::undoIt() +{ + BandDesignIntf* band = dynamic_cast(page()->reportItemByName(bandName)); + BandDesignIntf* bandToSwap = dynamic_cast(page()->reportItemByName(bandToSwapName)); + if (band && bandToSwap) + page()->pageItem()->swapBands(bandToSwap, band); } } diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 684df0b..e3c1763 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -435,6 +435,16 @@ namespace LimeReport { QVector m_newPos; }; + class BandSwapCommand : public AbstractPageCommand{ + public: + static CommandIf::Ptr create(PageDesignIntf* page, const QString& bandName, const QString& bandToSwapName); + bool doIt(); + void undoIt(); + private: + QString bandName; + QString bandToSwapName; + }; + class SizeChangedCommand : public AbstractPageCommand{ public: static CommandIf::Ptr create(PageDesignIntf* page, QVector& oldSize, QVector& newSize); diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 9e5c4ce..f13218d 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -568,6 +568,34 @@ void PageItemDesignIntf::bandDeleted(QObject *band) relocateBands(); } +void PageItemDesignIntf::swapBands(BandDesignIntf* band, BandDesignIntf* bandToSwap){ + int startIndex = std::min(band->minChildIndex(), bandToSwap->minChildIndex()); + +// int endIndex = std::max(band->maxChildIndex(), bandToSwap->maxChildIndex()); +// QList bandToMove; +// foreach(BandDesignIntf* curBand, m_bands){ +// if (curBand->bandIndex() > endIndex) +// bandToMove.append(curBand); +// } + + BandDesignIntf* firstMoveBand = (bandToSwap->bandIndex() > band->bandIndex()) ? bandToSwap: band; + + firstMoveBand->changeBandIndex(startIndex, true); + if (firstMoveBand == band){ + bandToSwap->changeBandIndex(firstMoveBand->maxChildIndex()+1,true); + } else { + band->changeBandIndex(firstMoveBand->maxChildIndex()+1, true); + } + relocateBands(); + +// int maxNewIndex = std::max(band->maxChildIndex(), bandToSwap->maxChildIndex()); +// if (maxNewIndex > endIndex){ +// foreach(BandDesignIntf* curBand, bandToMove){ +// curBand->setBandIndex(curBand->bandIndex()+(maxNewIndex - endIndex)); +// } +// } +} + void PageItemDesignIntf::bandGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry) { BandDesignIntf* band = dynamic_cast(object); @@ -596,33 +624,10 @@ void PageItemDesignIntf::bandGeometryChanged(QObject* object, QRectF newGeometry } if (curIndex != band->bandIndex()){ - int startIndex = std::min(band->minChildIndex(), bandToSwap->minChildIndex()); - -// int endIndex = std::max(band->maxChildIndex(), bandToSwap->maxChildIndex()); -// QList bandToMove; -// foreach(BandDesignIntf* curBand, m_bands){ -// if (curBand->bandIndex() > endIndex) -// bandToMove.append(curBand); -// } - - BandDesignIntf* firstMoveBand = (bandToSwap->bandIndex() > band->bandIndex()) ? bandToSwap: band; - - firstMoveBand->changeBandIndex(startIndex, true); - if (firstMoveBand == band){ - bandToSwap->changeBandIndex(firstMoveBand->maxChildIndex()+1,true); - } else { - band->changeBandIndex(firstMoveBand->maxChildIndex()+1, true); - } - -// int maxNewIndex = std::max(band->maxChildIndex(), bandToSwap->maxChildIndex()); -// if (maxNewIndex > endIndex){ -// foreach(BandDesignIntf* curBand, bandToMove){ -// curBand->setBandIndex(curBand->bandIndex()+(maxNewIndex - endIndex)); -// } -// } + //swapBands(band, bandToSwap); + page()->saveCommand(BandSwapCommand::create(page(), band->objectName(), bandToSwap->objectName()), true); } - relocateBands(); } diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index ef9b06d..aa66b0a 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -116,7 +116,8 @@ public: bool canContainChildren(){ return true;} bool resetPageNumber() const; void setResetPageNumber(bool resetPageNumber); - void updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager); + void updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager); + void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap); protected slots: void bandDeleted(QObject* band);