1 // actionblocksremove.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "actionblocksremove.h"
18 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_insert.h"
23 ActionBlocksRemove::ActionBlocksRemove(RS_EntityContainer & container, GraphicView & graphicView):
24 ActionInterface("Remove Block", container, graphicView)
28 ActionBlocksRemove::~ActionBlocksRemove()
32 void ActionBlocksRemove::trigger()
34 RS_DEBUG->print("ActionBlocksRemove::trigger");
38 RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());
40 // list of containers that might refer to the block via inserts:
41 QList<RS_EntityContainer *> containerList;
42 containerList.append(graphic);
43 RS_BlockList * blkLst = graphic->getBlockList();
45 for(uint bi=0; bi<blkLst->count(); bi++)
46 containerList.append(blkLst->at(bi));
50 for(int i=0; i<containerList.size(); i++)
52 RS_EntityContainer * cont = containerList[i];
53 // remove all inserts from the graphic:
60 for(RS_Entity * e=cont->firstEntity(RS2::ResolveNone); e!=NULL;
61 e=cont->nextEntity(RS2::ResolveNone))
63 if (e->rtti() == RS2::EntityInsert)
65 RS_Insert * ins = (RS_Insert *)e;
67 if (ins->getName() == block->getName())
69 cont->removeEntity(ins);
79 // close all windows that are editing this block:
81 RS_DIALOGFACTORY->closeEditBlockWindow(block);
83 // Now remove the block from the block list:
84 graphic->removeBlock(block);
85 graphic->updateInserts();
86 graphicView->redraw();
91 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
94 void ActionBlocksRemove::init(int status)
96 ActionInterface::init(status);