From 8c32925b855bdfc8be6de88496090b467fed7fa7 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 18 Feb 2016 22:33:15 +0300 Subject: [PATCH] =?UTF-8?q?fix=20#7=20=D0=94=D0=B8=D0=B7=D0=B0=D0=B9=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=20=D0=BF=D0=B0=D0=B4=D0=B0=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D1=85?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lrpagedesignintf.cpp | 77 ++++++++++++++++++++++++++++++------ src/lrpagedesignintf.h | 3 +- src/lrreportdesignwidget.cpp | 3 +- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/lrpagedesignintf.cpp b/src/lrpagedesignintf.cpp index c26b20f..e52c1d7 100644 --- a/src/lrpagedesignintf.cpp +++ b/src/lrpagedesignintf.cpp @@ -503,6 +503,27 @@ CommandIf::Ptr createBandDeleteCommand(PageDesignIntf* page, BandDesignIntf* ban } } +CommandIf::Ptr PageDesignIntf::removeReportItemCommand(BaseDesignIntf *item){ + BandDesignIntf* band = dynamic_cast(item); + if (band){ + CommandIf::Ptr command = createBandDeleteCommand(this,band); + return command; + } else { + LayoutDesignIntf* layout = dynamic_cast(item->parent()); + if (layout && (layout->childrenCount()==2)){ + CommandGroup::Ptr commandGroup = CommandGroup::create(); + commandGroup->addCommand(DeleteLayoutCommand::create(this, layout),false); + commandGroup->addCommand(DeleteItemCommand::create(this,item),false); + return commandGroup; + } else { + CommandIf::Ptr command = (dynamic_cast(item))? + DeleteLayoutCommand::create(this, dynamic_cast(item)) : + DeleteItemCommand::create(this, item) ; + return command; + } + } +} + void PageDesignIntf::removeReportItem(BaseDesignIntf *item, bool createComand) { @@ -1117,22 +1138,52 @@ void PageDesignIntf::paste() } } -void PageDesignIntf::deleteSelected(bool createCommand) +void PageDesignIntf::deleteSelected() { - int bandCount = 0; - foreach(QGraphicsItem* item, selectedItems()){ - BandDesignIntf* bd = dynamic_cast(item); - if (bd) bandCount++; - } - if (bandCount>1) { - QMessageBox::warning(0,tr("Warning"),tr("Multi band deletion not allowed")); - return; + if (selectedItems().count()==1){ + saveCommand(removeReportItemCommand(dynamic_cast(selectedItems().at(0)))); + } else { + + QList itemsToDelete = selectedItems(); + + + CommandGroup::Ptr commandGroup = CommandGroup::create(); + + QList bands; + QList::iterator it; + + for(it = itemsToDelete.begin(); it != itemsToDelete.end();){ + BandDesignIntf* band = dynamic_cast(*it); + if (band) { + bands.append(band); + it = itemsToDelete.erase(it); + } else { + ++it; + } + } + + foreach (BandDesignIntf* band, bands){ + foreach (QGraphicsItem* bandItem, band->childItems()) { + itemsToDelete.removeOne(bandItem); + } + } + + if (!itemsToDelete.isEmpty()){ + foreach(QGraphicsItem* item, itemsToDelete){ + if (!dynamic_cast(item)) + commandGroup->addCommand(removeReportItemCommand(dynamic_cast(item)),false); + } + } + + if (!bands.isEmpty()){ + foreach (BandDesignIntf* band, bands) { + commandGroup->addCommand(removeReportItemCommand(band),false); + } + } + + saveCommand(commandGroup); } - foreach(QGraphicsItem* item, selectedItems()){ - if (!dynamic_cast(item)) - removeReportItem(dynamic_cast(item),createCommand); - } } void PageDesignIntf::cut() diff --git a/src/lrpagedesignintf.h b/src/lrpagedesignintf.h index 49e308c..516da01 100644 --- a/src/lrpagedesignintf.h +++ b/src/lrpagedesignintf.h @@ -111,6 +111,7 @@ namespace LimeReport { BaseDesignIntf* addReportItem(const QString& itemType, QObject *owner=0, BaseDesignIntf *parent=0); BaseDesignIntf* createReportItem(const QString& itemType, QObject *owner=0, BaseDesignIntf *parent=0); void removeReportItem(BaseDesignIntf* item, bool createComand = true); + CommandIf::Ptr removeReportItemCommand(BaseDesignIntf *item); bool saveCommand(CommandIf::Ptr command, bool runCommand = true); bool isCanRedo(); @@ -194,7 +195,7 @@ namespace LimeReport { void redo(); void copy(); void paste(); - void deleteSelected(bool createCommand); + void deleteSelected(); void cut(); void setToSaved(); void bringToFront(); diff --git a/src/lrreportdesignwidget.cpp b/src/lrreportdesignwidget.cpp index 2296f42..91fef52 100644 --- a/src/lrreportdesignwidget.cpp +++ b/src/lrreportdesignwidget.cpp @@ -251,7 +251,7 @@ void ReportDesignWidget::deleteItem(QGraphicsItem *item){ } void ReportDesignWidget::deleteSelectedItems(){ - activePage()->deleteSelected(true); + activePage()->deleteSelected(); } QStringList ReportDesignWidget::datasourcesNames(){ @@ -405,7 +405,6 @@ void ReportDesignWidget::setFont(const QFont& font) void ReportDesignWidget::setTextAlign(const bool& horizontalAlign, const Qt::AlignmentFlag& alignment) { - //activePage()->setTextAlign(alignment); activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment); }