1 /****************************************************************************
2 ** $Id: rs_actionblocksremove.cpp 2372 2005-04-29 11:44:54Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionblocksremove.h"
30 #include "rs_graphic.h"
31 #include "rs_insert.h"
32 #include "rs_dialogfactory.h"
34 RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container,
35 RS_GraphicView & graphicView):
36 RS_ActionInterface("Remove Block", container, graphicView)
40 QAction * RS_ActionBlocksRemove::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
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"));
50 void RS_ActionBlocksRemove::trigger()
52 RS_DEBUG->print("RS_ActionBlocksRemove::trigger");
56 RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());
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();
64 for(uint bi=0; bi<blkLst->count(); bi++)
65 containerList.append(blkLst->at(bi));
69 // for (RS_EntityContainer * cont=containerList.first(); cont!=NULL;
70 // cont=containerList.next())
71 for(int i=0; i<containerList.size(); i++)
73 RS_EntityContainer * cont = containerList[i];
74 // remove all inserts from the graphic:
81 for (RS_Entity* e=cont->firstEntity(RS2::ResolveNone); e!=NULL;
82 e=cont->nextEntity(RS2::ResolveNone))
84 if (e->rtti() == RS2::EntityInsert)
86 RS_Insert * ins = (RS_Insert *)e;
88 if (ins->getName() == block->getName())
90 cont->removeEntity(ins);
100 // close all windows that are editing this block:
101 if (RS_DIALOGFACTORY != NULL)
102 RS_DIALOGFACTORY->closeEditBlockWindow(block);
104 // Now remove the block from the block list:
105 graphic->removeBlock(block);
106 graphic->updateInserts();
107 graphicView->redraw();
112 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
115 void RS_ActionBlocksRemove::init(int status)
117 RS_ActionInterface::init(status);