0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

Bands relocation redo, undo fixed

This commit is contained in:
Arin Alexander 2018-07-13 17:40:49 +03:00
parent d5c0c1778e
commit 6641215cc0
5 changed files with 82 additions and 33 deletions

View File

@ -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}\"

View File

@ -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<BandDesignIntf*>(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<ReportItemPos> 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<BandDesignIntf*>(page()->reportItemByName(bandName));
BandDesignIntf* bandToSwap = dynamic_cast<BandDesignIntf*>(page()->reportItemByName(bandToSwapName));
if (band && bandToSwap){
page()->pageItem()->swapBands(band, bandToSwap);
return true;
}
return false;
}
void BandSwapCommand::undoIt()
{
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(page()->reportItemByName(bandName));
BandDesignIntf* bandToSwap = dynamic_cast<BandDesignIntf*>(page()->reportItemByName(bandToSwapName));
if (band && bandToSwap)
page()->pageItem()->swapBands(bandToSwap, band);
}
}

View File

@ -435,6 +435,16 @@ namespace LimeReport {
QVector<ReportItemPos> 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<ReportItemSize>& oldSize, QVector<ReportItemSize>& newSize);

View File

@ -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<BandDesignIntf*> 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<BandDesignIntf*>(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<BandDesignIntf*> 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();
}

View File

@ -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);