fix #7 Дизайнер падает при удалении нескольких объектов

This commit is contained in:
Arin Alexander 2016-02-18 22:33:15 +03:00
parent 8d6e9d36e4
commit 8c32925b85
3 changed files with 67 additions and 16 deletions

View File

@ -503,6 +503,27 @@ CommandIf::Ptr createBandDeleteCommand(PageDesignIntf* page, BandDesignIntf* ban
} }
} }
CommandIf::Ptr PageDesignIntf::removeReportItemCommand(BaseDesignIntf *item){
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(item);
if (band){
CommandIf::Ptr command = createBandDeleteCommand(this,band);
return command;
} else {
LayoutDesignIntf* layout = dynamic_cast<LayoutDesignIntf*>(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<LayoutDesignIntf*>(item))?
DeleteLayoutCommand::create(this, dynamic_cast<LayoutDesignIntf*>(item)) :
DeleteItemCommand::create(this, item) ;
return command;
}
}
}
void PageDesignIntf::removeReportItem(BaseDesignIntf *item, bool createComand) void PageDesignIntf::removeReportItem(BaseDesignIntf *item, bool createComand)
{ {
@ -1117,24 +1138,54 @@ void PageDesignIntf::paste()
} }
} }
void PageDesignIntf::deleteSelected(bool createCommand) void PageDesignIntf::deleteSelected()
{ {
int bandCount = 0; if (selectedItems().count()==1){
foreach(QGraphicsItem* item, selectedItems()){ saveCommand(removeReportItemCommand(dynamic_cast<BaseDesignIntf*>(selectedItems().at(0))));
BandDesignIntf* bd = dynamic_cast<BandDesignIntf*>(item); } else {
if (bd) bandCount++;
QList<QGraphicsItem*> itemsToDelete = selectedItems();
CommandGroup::Ptr commandGroup = CommandGroup::create();
QList<BandDesignIntf*> bands;
QList<QGraphicsItem*>::iterator it;
for(it = itemsToDelete.begin(); it != itemsToDelete.end();){
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(*it);
if (band) {
bands.append(band);
it = itemsToDelete.erase(it);
} else {
++it;
} }
if (bandCount>1) {
QMessageBox::warning(0,tr("Warning"),tr("Multi band deletion not allowed"));
return;
} }
foreach(QGraphicsItem* item, selectedItems()){ foreach (BandDesignIntf* band, bands){
if (!dynamic_cast<PageItemDesignIntf*>(item)) foreach (QGraphicsItem* bandItem, band->childItems()) {
removeReportItem(dynamic_cast<BaseDesignIntf*>(item),createCommand); itemsToDelete.removeOne(bandItem);
} }
} }
if (!itemsToDelete.isEmpty()){
foreach(QGraphicsItem* item, itemsToDelete){
if (!dynamic_cast<PageItemDesignIntf*>(item))
commandGroup->addCommand(removeReportItemCommand(dynamic_cast<BaseDesignIntf*>(item)),false);
}
}
if (!bands.isEmpty()){
foreach (BandDesignIntf* band, bands) {
commandGroup->addCommand(removeReportItemCommand(band),false);
}
}
saveCommand(commandGroup);
}
}
void PageDesignIntf::cut() void PageDesignIntf::cut()
{ {
CommandIf::Ptr command = CutCommand::create(this); CommandIf::Ptr command = CutCommand::create(this);

View File

@ -111,6 +111,7 @@ namespace LimeReport {
BaseDesignIntf* addReportItem(const QString& itemType, QObject *owner=0, BaseDesignIntf *parent=0); BaseDesignIntf* addReportItem(const QString& itemType, QObject *owner=0, BaseDesignIntf *parent=0);
BaseDesignIntf* createReportItem(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); void removeReportItem(BaseDesignIntf* item, bool createComand = true);
CommandIf::Ptr removeReportItemCommand(BaseDesignIntf *item);
bool saveCommand(CommandIf::Ptr command, bool runCommand = true); bool saveCommand(CommandIf::Ptr command, bool runCommand = true);
bool isCanRedo(); bool isCanRedo();
@ -194,7 +195,7 @@ namespace LimeReport {
void redo(); void redo();
void copy(); void copy();
void paste(); void paste();
void deleteSelected(bool createCommand); void deleteSelected();
void cut(); void cut();
void setToSaved(); void setToSaved();
void bringToFront(); void bringToFront();

View File

@ -251,7 +251,7 @@ void ReportDesignWidget::deleteItem(QGraphicsItem *item){
} }
void ReportDesignWidget::deleteSelectedItems(){ void ReportDesignWidget::deleteSelectedItems(){
activePage()->deleteSelected(true); activePage()->deleteSelected();
} }
QStringList ReportDesignWidget::datasourcesNames(){ QStringList ReportDesignWidget::datasourcesNames(){
@ -405,7 +405,6 @@ void ReportDesignWidget::setFont(const QFont& font)
void ReportDesignWidget::setTextAlign(const bool& horizontalAlign, const Qt::AlignmentFlag& alignment) void ReportDesignWidget::setTextAlign(const bool& horizontalAlign, const Qt::AlignmentFlag& alignment)
{ {
//activePage()->setTextAlign(alignment);
activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment); activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment);
} }