]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionblocksremove.cpp
d51e5b0eb7ce21bc302548e0e22c7ee8d046eaf5
[architektonas] / src / actions / rs_actionblocksremove.cpp
1 /****************************************************************************
2 ** $Id: rs_actionblocksremove.cpp 2372 2005-04-29 11:44:54Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionblocksremove.h"
28
29 #include "rs_block.h"
30 #include "drawing.h"
31 #include "rs_insert.h"
32 #include "rs_dialogfactory.h"
33
34 RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container,
35         RS_GraphicView & graphicView):
36         RS_ActionInterface("Remove Block", container, graphicView)
37 {
38 }
39
40 QAction * RS_ActionBlocksRemove::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
41 {
42         QAction * action = new QAction(tr("&Remove Block"), 0);
43 //        QAction* action = new QAction(tr("Remove Block"), tr("&Remove Block"),
44 //                             QKeySequence(), NULL);
45                 action->setStatusTip(tr("Remove Block"));
46
47                 return action;
48 }
49
50 void RS_ActionBlocksRemove::trigger()
51 {
52         RS_DEBUG->print("RS_ActionBlocksRemove::trigger");
53
54         if (graphic!=NULL)
55         {
56                 RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());
57
58                 // list of containers that might refer to the block via inserts:
59 //        Q3PtrList<RS_EntityContainer> containerList;
60                 QList<RS_EntityContainer *> containerList;
61                 containerList.append(graphic);
62                 RS_BlockList * blkLst = graphic->getBlockList();
63
64                 for(uint bi=0; bi<blkLst->count(); bi++)
65                         containerList.append(blkLst->at(bi));
66
67                 if (block != NULL)
68                 {
69 //                      for (RS_EntityContainer * cont=containerList.first(); cont!=NULL;
70 //                              cont=containerList.next())
71                         for(int i=0; i<containerList.size(); i++)
72                         {
73                                 RS_EntityContainer * cont = containerList[i];
74                                 // remove all inserts from the graphic:
75                                 bool done;
76
77                                 do
78                                 {
79                                         done = true;
80
81                                         for (RS_Entity* e=cont->firstEntity(RS2::ResolveNone); e!=NULL;
82                                                 e=cont->nextEntity(RS2::ResolveNone))
83                                         {
84                                                 if (e->rtti() == RS2::EntityInsert)
85                                                 {
86                                                         RS_Insert * ins = (RS_Insert *)e;
87
88                                                         if (ins->getName() == block->getName())
89                                                         {
90                                                                 cont->removeEntity(ins);
91                                                                 done = false;
92                                                                 break;
93                                                         }
94                                                 }
95                                         }
96                                 }
97                                 while (!done);
98                         }
99
100                         // close all windows that are editing this block:
101                         if (RS_DIALOGFACTORY != NULL)
102                                 RS_DIALOGFACTORY->closeEditBlockWindow(block);
103
104                         // Now remove the block from the block list:
105                         graphic->removeBlock(block);
106                         graphic->updateInserts();
107                         graphicView->redraw();
108                 }
109         }
110
111         finish();
112         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
113 }
114
115 void RS_ActionBlocksRemove::init(int status)
116 {
117         RS_ActionInterface::init(status);
118         trigger();
119 }