1 // rs_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 "rs_actionblocksremove.h"
18 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_insert.h"
23 RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container, GraphicView & graphicView):
24 RS_ActionInterface("Remove Block", container, graphicView)
28 RS_ActionBlocksRemove::~RS_ActionBlocksRemove()
32 void RS_ActionBlocksRemove::trigger()
34 RS_DEBUG->print("RS_ActionBlocksRemove::trigger");
38 RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());
40 // list of containers that might refer to the block via inserts:
41 // Q3PtrList<RS_EntityContainer> containerList;
42 QList<RS_EntityContainer *> containerList;
43 containerList.append(graphic);
44 RS_BlockList * blkLst = graphic->getBlockList();
46 for (uint bi = 0; bi < blkLst->count(); bi++)
47 containerList.append(blkLst->at(bi));
51 // for (RS_EntityContainer * cont=containerList.first(); cont!=NULL;
52 // cont=containerList.next())
53 for (int i = 0; i < containerList.size(); i++)
55 RS_EntityContainer * cont = containerList[i];
56 // remove all inserts from the graphic:
63 for (RS_Entity * e = cont->firstEntity(RS2::ResolveNone); e != NULL;
64 e = cont->nextEntity(RS2::ResolveNone))
65 if (e->rtti() == RS2::EntityInsert)
67 RS_Insert * ins = (RS_Insert *)e;
69 if (ins->getName() == block->getName())
71 cont->removeEntity(ins);
80 // close all windows that are editing this block:
81 if (RS_DIALOGFACTORY != NULL)
82 RS_DIALOGFACTORY->closeEditBlockWindow(block);
84 // Now remove the block from the block list:
85 graphic->removeBlock(block);
86 graphic->updateInserts();
87 graphicView->redraw();
92 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
95 void RS_ActionBlocksRemove::init(int status)
97 RS_ActionInterface::init(status);