]> Shamusworld >> Repos - architektonas/blob - src/actions/actionblocksattributes.cpp
7e6d09d881c0273542b40abb4542a0c9f16bc6b6
[architektonas] / src / actions / actionblocksattributes.cpp
1 // actionblocksattributes.cpp
2 //
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
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  07/12/2010  Added this text. :-)
13 //
14
15 #include "actionblocksattributes.h"
16
17 #include "drawing.h"
18 #include "rs_dialogfactory.h"
19
20 ActionBlocksAttributes::ActionBlocksAttributes(
21         RS_EntityContainer & container, GraphicView & graphicView):
22         ActionInterface("Edit Block Attributes", container, graphicView)
23 {
24 }
25
26 ActionBlocksAttributes::~ActionBlocksAttributes()
27 {
28 }
29
30 void ActionBlocksAttributes::trigger()
31 {
32         RS_DEBUG->print("editing block attributes");
33
34         if (graphic && RS_DIALOGFACTORY)
35         {
36                 RS_Block * block = graphic->getActiveBlock();
37                 RS_BlockList * blockList = graphic->getBlockList();
38
39                 if (blockList && block)
40                 {
41                         QString oldName = block->getName();
42                         RS_BlockData d = RS_DIALOGFACTORY->requestBlockAttributesDialog(blockList);
43
44                         if (d.isValid())
45                         {
46                                 QString newName = d.name;
47                                 blockList->rename(block, newName);
48
49                                 // update the name of all inserts:
50                                 graphic->renameInserts(oldName, newName);
51                                 graphic->addBlockNotification();
52                         }
53                 }
54         }
55
56         finish();
57 }
58
59 void ActionBlocksAttributes::init(int status)
60 {
61         ActionInterface::init(status);
62         trigger();
63 }