HAL
action_rename_object.cpp
Go to the documentation of this file.
2 
7 #include "gui/gui_globals.h"
8 
9 #include <QDebug>
10 
11 namespace hal
12 {
14  {
15  }
16 
18 
20  {
21  return new ActionRenameObject;
22  }
23 
25  {
27  }
28 
30  {
31  cryptoHash.addData(mNewName.toUtf8());
32  }
33 
35  {
36  xmlOut.writeTextElement("name", mNewName);
37  }
38 
40  {
41  while (xmlIn.readNextStartElement())
42  {
43  if (xmlIn.name() == "name")
44  mNewName = xmlIn.readElementText();
45  }
46  }
47 
49  {
50  QString oldName;
51  Module* mod;
52  Gate* gat;
53  Net* net;
54  GraphContext* ctx;
55  ContextDirectory* ctxDir;
56 
57  switch (mObject.type())
58  {
61  if (mod)
62  {
63  oldName = QString::fromStdString(mod->get_name());
64  mod->set_name(mNewName.toStdString());
65  }
66  else
67  return false;
68  break;
71  if (gat)
72  {
73  oldName = QString::fromStdString(gat->get_name());
74  gat->set_name(mNewName.toStdString());
75  }
76  else
77  {
78  return false;
79  }
80  break;
83  if (net)
84  {
85  oldName = QString::fromStdString(net->get_name());
86  net->set_name(mNewName.toStdString());
87  }
88  else
89  {
90  return false;
91  }
92  break;
95  break;
98  if (ctx)
99  {
100  oldName = ctx->name();
102  }
103  else
104  {
105  return false;
106  }
107  break;
110  if (ctxDir)
111  {
112  oldName = ctxDir->name();
114  }
115  else
116  {
117  return false;
118  }
119  break;
120 
121  default:
122  return false;
123  }
124  ActionRenameObject* undo = new ActionRenameObject(oldName);
125  undo->setObject(mObject);
126 
127  mUndoAction = undo;
128  return UserAction::exec();
129  }
130 } // namespace hal
UserActionFactory for ActionRenameObject.
static ActionRenameObjectFactory * sFactory
QString tagname() const override
void readFromXml(QXmlStreamReader &xmlIn) override
ActionRenameObject(const QString &name=QString())
void writeToXml(QXmlStreamWriter &xmlOut) const override
void addToHash(QCryptographicHash &cryptoHash) const override
GroupingManagerWidget * getGroupingManagerWidget()
Definition: gate.h:58
const std::string & get_name() const
Definition: gate.cpp:105
void set_name(const std::string &name)
Definition: gate.cpp:110
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
QString name() const
void renameContextDirectoryAction(ContextDirectory *ctxDir, const QString &newName)
void renameGraphContextAction(GraphContext *ctx, const QString &newName)
GraphContext * getContextById(u32 id) const
ContextDirectory * getDirectoryById(u32 id) const
GroupingTableModel * getModel() const
QString renameGrouping(u32 id, const QString &groupingName)
void set_name(const std::string &name)
Definition: module.cpp:92
std::string get_name() const
Definition: module.cpp:87
Definition: net.h:58
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
The UserActionFactory is the abstract base class for registration.
Definition: user_action.h:225
QString tagname() const
Definition: user_action.h:242
The UserAction class is the abstract base class for user interactions.
Definition: user_action.h:57
UserAction * mUndoAction
Definition: user_action.h:186
virtual bool exec()
Definition: user_action.cpp:23
virtual void setObject(const UserActionObject &obj)
Definition: user_action.cpp:32
UserActionObject mObject
Definition: user_action.h:183
UserActionObjectType::ObjectType type() const
ContentManager * gContentManager
Definition: plugin_gui.cpp:78
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
Netlist * gNetlist
Definition: plugin_gui.cpp:80
Net * net
void addData(const char *data, int length)
QString fromStdString(const std::string &str)
std::string toStdString() const const
QByteArray toUtf8() const const
QStringRef name() const const
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void writeTextElement(const QString &qualifiedName, const QString &text)