diff --git a/common.pri b/common.pri index 59b0769..739441b 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 = 95 +LIMEREPORT_VERSION_RELEASE = 96 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 e0f1747..8fc4cc7 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -2261,7 +2261,7 @@ bool BandSwapCommand::doIt() { BandDesignIntf* band = dynamic_cast(page()->reportItemByName(bandName)); BandDesignIntf* bandToSwap = dynamic_cast(page()->reportItemByName(bandToSwapName)); - if (band && bandToSwap){ + if (page() && band && bandToSwap){ page()->pageItem()->swapBands(band, bandToSwap); return true; } @@ -2272,9 +2272,32 @@ void BandSwapCommand::undoIt() { BandDesignIntf* band = dynamic_cast(page()->reportItemByName(bandName)); BandDesignIntf* bandToSwap = dynamic_cast(page()->reportItemByName(bandToSwapName)); - if (band && bandToSwap) + if (page() && band && bandToSwap) page()->pageItem()->swapBands(bandToSwap, band); } +CommandIf::Ptr BandMoveFromToCommand::create(PageDesignIntf* page, int from, int to) +{ + BandMoveFromToCommand* command = new BandMoveFromToCommand(); + command->setPage(page); + command->from = from; + command->to = to; + return CommandIf::Ptr(command); +} + +bool BandMoveFromToCommand::doIt() +{ + if (page() && from != to) { + page()->pageItem()->moveBandFromTo(from, to); + return true; + } + return false; +} + +void BandMoveFromToCommand::undoIt() +{ + if (page()) page()->pageItem()->moveBandFromTo(to, from); +} + } diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index e3c1763..9c48d8a 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -445,6 +445,17 @@ namespace LimeReport { QString bandToSwapName; }; + class BandMoveFromToCommand : public AbstractPageCommand{ + public: + static CommandIf::Ptr create(PageDesignIntf* page, int from, int to); + bool doIt(); + void undoIt(); + private: + int from; + int to; + }; + + 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 6ae6fc7..961127a 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -577,7 +577,7 @@ void PageItemDesignIntf::swapBands(BandDesignIntf* band, BandDesignIntf* bandToS QList bandToMove; foreach(BandDesignIntf* curBand, m_bands){ if ( curBand->bandIndex() > moveIndex && curBand->bandIndex() < secondIndex && - curBand->bandType() == BandDesignIntf::Data && + curBand->bandType() == band->bandType() && curBand != band && curBand != bandToSwap ) bandToMove.append(curBand); @@ -587,7 +587,9 @@ void PageItemDesignIntf::swapBands(BandDesignIntf* band, BandDesignIntf* bandToS firstMoveBand->changeBandIndex(firstIndex, true); moveIndex = firstMoveBand->maxChildIndex() + 1; + moveIndex = firstIndex; qSort(bandToMove.begin(), bandToMove.end(), bandIndexLessThen); + foreach(BandDesignIntf* curBand, bandToMove){ curBand->changeBandIndex(moveIndex,true); moveIndex = curBand->maxChildIndex() + 1; @@ -602,16 +604,63 @@ void PageItemDesignIntf::swapBands(BandDesignIntf* band, BandDesignIntf* bandToS } +void PageItemDesignIntf::moveBandFromTo(int from, int to) +{ + BandDesignIntf* firstBand = 0; + BandDesignIntf* secondBand = 0; + + int firstIndex = std::min(from,to); + int secondIndex = std::max(from,to); + QList bandsToMove; + int moveIndex = 0; + + foreach(BandDesignIntf* band, bands()){ + if (band->bandIndex() == from){ + firstBand = band; + } + if (band->bandIndex() == to){ + secondBand = band; + bandsToMove.append(band); + } + } + + foreach(BandDesignIntf* curBand, m_bands){ + if ( curBand->bandIndex() > firstIndex && curBand->bandIndex() < secondIndex && + curBand->bandType() == firstBand->bandType() && + curBand != firstBand + ) + bandsToMove.append(curBand); + } + qSort(bandsToMove.begin(), bandsToMove.end(), bandIndexLessThen); + + + if (from > to){ + firstBand->changeBandIndex(secondBand->minChildIndex(), true); + moveIndex = firstBand->maxChildIndex()+1; + } else { + moveIndex = firstBand->minChildIndex(); + firstBand->changeBandIndex(secondBand->minChildIndex(), true); + } + + foreach(BandDesignIntf* curBand, bandsToMove){ + curBand->changeBandIndex(moveIndex,true); + moveIndex = curBand->maxChildIndex() + 1; + } + + relocateBands(); + +} + void PageItemDesignIntf::bandGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry) { BandDesignIntf* band = dynamic_cast(object); int curIndex = band->bandIndex(); BandDesignIntf* bandToSwap = 0; foreach(BandDesignIntf* curBand, bands()){ - if (newGeometry.y()>oldGeometry.y()) { + if (newGeometry.y() > oldGeometry.y()) { if (curBand->bandType() == band->bandType() - && curIndexbandIndex() - && (curBand->pos().y()+(curBand->height()/2))bandIndex() + && (curBand->pos().y() + (curBand->height()/2)) < newGeometry.y() && curBand->parentBand() == band->parentBand()) { curIndex = curBand->bandIndex(); @@ -620,7 +669,7 @@ void PageItemDesignIntf::bandGeometryChanged(QObject* object, QRectF newGeometry } else { if (curBand->bandType() == band->bandType() && curIndex>curBand->bandIndex() - && (curBand->pos().y()+(curBand->height()/2))>newGeometry.y() + && (curBand->pos().y() + (curBand->height()/2)) > newGeometry.y() && curBand->parentBand() == band->parentBand()) { curIndex = curBand->bandIndex(); @@ -629,10 +678,9 @@ void PageItemDesignIntf::bandGeometryChanged(QObject* object, QRectF newGeometry } } if (curIndex != band->bandIndex()){ - //swapBands(band, bandToSwap); - page()->saveCommand(BandSwapCommand::create(page(), band->objectName(), bandToSwap->objectName()), true); - + //page()->saveCommand(BandSwapCommand::create(page(), band->objectName(), bandToSwap->objectName()), true); + page()->saveCommand(BandMoveFromToCommand::create(page(), band->bandIndex(), bandToSwap->bandIndex()), true); } relocateBands(); } diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index aa66b0a..2287cf8 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -117,7 +117,8 @@ public: bool resetPageNumber() const; void setResetPageNumber(bool resetPageNumber); void updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager); - void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap); + void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap); + void moveBandFromTo(int from, int to); protected slots: void bandDeleted(QObject* band);