diff --git a/common.pri b/common.pri index 9fc72a2..3caf5ac 100644 --- a/common.pri +++ b/common.pri @@ -105,7 +105,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 9f60781..f3cf433 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -871,10 +871,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(); @@ -910,16 +917,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() @@ -2380,5 +2385,33 @@ void InsertVLayoutCommand::undoIt() } } +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 8e228c0..ff7490f 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -452,6 +452,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 0454c53..dc7a404 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -702,6 +702,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); @@ -730,33 +758,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 abcdb72..037b06a 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -123,7 +123,8 @@ public: bool canContainChildren() const{ 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); bool isExtendedInDesignMode() const; void setExtendedInDesignMode(bool isExtendedInDesignMode);