diff --git a/common.pri b/common.pri index ddf7199..aa9184b 100644 --- a/common.pri +++ b/common.pri @@ -120,7 +120,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 123 +LIMEREPORT_VERSION_RELEASE = 124 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index 61f6b0a..47d73ea 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -425,10 +425,23 @@ int BandDesignIntf::maxChildIndex(QSet ignoredBands) return curIndex; } +int BandDesignIntf::rootIndex(BandDesignIntf* parentBand) +{ + return rootBand(parentBand)->bandIndex(); +} + +BandDesignIntf *BandDesignIntf::rootBand(BandDesignIntf* parentBand) +{ + BandDesignIntf* currentBand = this; + while (currentBand->parentBand() && currentBand->parentBand() != parentBand) + currentBand = currentBand->parentBand(); + return currentBand; +} + int BandDesignIntf::minChildIndex(BandDesignIntf::BandsType bandType){ int curIndex = bandIndex(); foreach(BandDesignIntf* childBand, childBands()){ - if (curIndex>childBand->bandIndex() && (childBand->bandType()>bandType)){ + if (curIndex > childBand->bandIndex() && (childBand->bandType() > bandType)){ curIndex = childBand->bandIndex(); } } @@ -440,7 +453,7 @@ int BandDesignIntf::minChildIndex(QSet ignoredBands) int curIndex = bandIndex(); foreach(BandDesignIntf* childBand, childBands()){ if (!ignoredBands.contains(childBand->bandType()) && childBand->bandIndex() < bandIndex()){ - curIndex = std::min(curIndex, childBand->maxChildIndex(ignoredBands)); + curIndex = std::min(curIndex, childBand->minChildIndex(ignoredBands)); } } return curIndex; diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index 8faf9c8..a6e09be 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -183,6 +183,9 @@ public: int maxChildIndex(BandDesignIntf::BandsType bandType) const; int maxChildIndex(QSet ignoredBands = QSet()) const; + int rootIndex(BandDesignIntf *parentBand); + BandDesignIntf* rootBand(BandDesignIntf *parentBand); + BandDesignIntf* parentBand() const {return m_parentBand;} QList childBands() const{return m_childBands;} diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 260584d..6ef7815 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -2504,8 +2504,13 @@ CommandIf::Ptr BandMoveFromToCommand::create(PageDesignIntf* page, int from, int bool BandMoveFromToCommand::doIt() { if (page() && page()->pageItem() && from != to) { - page()->pageItem()->moveBandFromTo(from, to); - return true; + BandDesignIntf* fromBand = page()->pageItem()->bandByIndex(from); + reverceTo = fromBand->minChildIndex(); + if (fromBand){ + page()->pageItem()->moveBandFromTo(from, to); + reverceFrom = fromBand->bandIndex(); + return true; + } } return false; } @@ -2513,7 +2518,7 @@ bool BandMoveFromToCommand::doIt() void BandMoveFromToCommand::undoIt() { if (page() && page()->pageItem()) - page()->pageItem()->moveBandFromTo(to, from); + page()->pageItem()->moveBandFromTo(reverceFrom, reverceTo); } } diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 6475373..0a3c914 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -467,6 +467,8 @@ namespace LimeReport { private: int from; int to; + int reverceFrom; + int reverceTo; }; diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index b0cdff8..8663533 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -771,47 +771,68 @@ void PageItemDesignIntf::swapBands(BandDesignIntf* band, BandDesignIntf* bandToS } +QList PageItemDesignIntf::createBandGroup(int beginIndex, int endIndex) +{ + QList result; + foreach(BandDesignIntf* curBand, m_bands){ + if ( curBand->bandIndex() >= beginIndex && curBand->bandIndex() <= endIndex) + result.append(curBand); + } + qSort(result.begin(), result.end(), bandIndexLessThen); + return result; +} + 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; + BandDesignIntf* fromBand = 0; + BandDesignIntf* toBand = 0; foreach(BandDesignIntf* band, bands()){ if (band->bandIndex() == from){ - firstBand = band; + fromBand = band->rootBand(band->parentBand()); } if (band->bandIndex() == to){ - secondBand = band; - bandsToMove.append(band); + toBand = band->rootBand(band->parentBand()); } + if (fromBand && toBand) break; } - 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 (!fromBand || !toBand) return; - - if (from > to){ - firstBand->changeBandIndex(secondBand->minChildIndex(), true); - moveIndex = firstBand->maxChildIndex()+1; + int beginIndex = 0; + int endIndex = 0; + if (from < to){ + beginIndex = fromBand->maxChildIndex()+1; + endIndex = toBand->maxChildIndex(); } else { - moveIndex = firstBand->minChildIndex(); - firstBand->changeBandIndex(secondBand->minChildIndex(), true); + beginIndex = toBand->minChildIndex(); + endIndex = fromBand->minChildIndex()-1; } - foreach(BandDesignIntf* curBand, bandsToMove){ - curBand->changeBandIndex(moveIndex,true); - moveIndex = curBand->maxChildIndex() + 1; + QList firstGroup = createBandGroup(fromBand->minChildIndex(), fromBand->maxChildIndex()); + QList secondGroup = createBandGroup(beginIndex, endIndex); + + if (from < to){ + int currentIndex = fromBand->minChildIndex(); + foreach(BandDesignIntf* band, secondGroup){ + band->setBandIndex(currentIndex); + currentIndex++; + } + foreach(BandDesignIntf* band, firstGroup){ + band->setBandIndex(currentIndex); + currentIndex++; + } + } else { + int currentIndex = toBand->minChildIndex(); + foreach(BandDesignIntf* band, firstGroup){ + band->setBandIndex(currentIndex); + currentIndex++; + } + foreach(BandDesignIntf* band, secondGroup){ + band->setBandIndex(currentIndex); + currentIndex++; + } } relocateBands(); diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 09fa2d6..29f6498 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -137,6 +137,8 @@ public: void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap); void moveBandFromTo(int from, int to); + QList createBandGroup(int beginIndex, int endIndex); + bool isExtendedInDesignMode() const; void setExtendedInDesignMode(bool isExtendedInDesignMode); int extendedHeight() const;