| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "rs_actionblocksremove.h" |
| |
|
| | #include "rs_debug.h" |
| | #include "rs_dialogfactory.h" |
| | #include "rs_dialogfactoryinterface.h" |
| | #include "rs_graphic.h" |
| | #include "rs_insert.h" |
| |
|
| | class RS_BlockList; |
| |
|
| | RS_ActionBlocksRemove::RS_ActionBlocksRemove(LC_ActionContext *actionContext) |
| | :RS_ActionInterface("Remove Block", actionContext, RS2::ActionBlocksRemove) {} |
| |
|
| | void RS_ActionBlocksRemove::trigger() { |
| | RS_DEBUG->print("RS_ActionBlocksRemove::trigger"); |
| |
|
| | if (!(m_graphic && m_document)) { |
| | finish(false); |
| | return; |
| | } |
| |
|
| | RS_BlockList *blockList = m_graphic->getBlockList(); |
| | QList<RS_Block *> blocks = RS_DIALOGFACTORY->requestSelectedBlocksRemovalDialog(blockList); |
| |
|
| | if (blocks.isEmpty()) { |
| | finish(false); |
| | return; |
| | } |
| |
|
| | |
| | std::vector<RS_EntityContainer *> containerList; |
| | containerList.push_back(m_graphic); |
| | for (int bi = 0; bi < blockList->count(); bi++) { |
| | containerList.push_back(blockList->at(bi)); |
| | } |
| |
|
| | undoCycleStart(); |
| |
|
| | for (auto block: blocks) { |
| | if (nullptr == block) { |
| | continue; |
| | } |
| | for (auto cont: containerList) { |
| | |
| | bool done; |
| | do { |
| | done = true; |
| | for (auto e: *cont) { |
| | if (e->is(RS2::EntityInsert)) { |
| | auto *ins = static_cast<RS_Insert *>(e); |
| | if (ins->getName() == block->getName() && !ins->isUndone()) { |
| | m_document->addUndoable(ins); |
| | ins->setUndoState(true); |
| | done = false; |
| | break; |
| | } |
| | } |
| | } |
| | } while (!done); |
| | } |
| |
|
| | |
| | block->selectedInBlockList(false); |
| | if (block == blockList->getActive()) { |
| | blockList->activate(nullptr); |
| | } |
| |
|
| | |
| | RS_DIALOGFACTORY->closeEditBlockWindow(block); |
| |
|
| | |
| | block->setUndoState(true); |
| | m_document->addUndoable(block); |
| | } |
| | undoCycleEnd(); |
| |
|
| | m_graphic->addBlockNotification(); |
| | m_graphic->updateInserts(); |
| | redrawDrawing(); |
| | blockList->activate(nullptr); |
| |
|
| | finish(false); |
| | updateSelectionWidget(); |
| | } |
| |
|
| | void RS_ActionBlocksRemove::init(int status) { |
| | RS_ActionInterface::init(status); |
| | trigger(); |
| | } |
| |
|