HAL
action_move_item.cpp
Go to the documentation of this file.
3 #include <QStringList>
5 #include "gui/gui_globals.h"
10 
11 namespace hal
12 {
14  : UserActionFactory("MoveNode") {;}
15 
17 
19  {
20  return new ActionMoveItem;
21  }
22 
23  ActionMoveItem::ActionMoveItem(u32 tgtId, u32 srcId, int tgtRow)
24  : mSourceParentId(srcId), mTargetParentId(tgtId), mTargetRow(tgtRow)
25  {;}
26 
28  {
30  }
31 
33  {
34  cryptoHash.addData((char*)(&mTargetParentId), sizeof(u32));
35  }
36 
38  {
39  xmlOut.writeTextElement("target_parent_id", QString("%1").arg(mTargetParentId));
40  if (mSourceParentId)
41  xmlOut.writeTextElement("source_parent_id", QString("%1").arg(mSourceParentId));
42  }
43 
45  {
46  while (xmlIn.readNextStartElement())
47  {
48  if (xmlIn.name() == "target_parent_id")
49  mTargetParentId = xmlIn.readElementText().toUInt();
50  if (xmlIn.name() == "source_parent_id")
51  mSourceParentId = xmlIn.readElementText().toUInt();
52  }
53  }
54 
56  {
57  if (!mObject.id()) return false;
58 
59  BaseTreeItem* bti = nullptr;
60  bool isDirectory = false;
61 
62  switch (mObject.type()) {
65  break;
68  isDirectory = true;
69  break;
70  default:
71  break;
72  }
73  if (!bti) return false;
74 
75  if (!mSourceParentId)
76  {
77  ContextTreeItem* parCti = dynamic_cast<ContextTreeItem*>(bti->getParent());
78  if (parCti) mSourceParentId = parCti->getId();
79  }
80 
81  int sourceRow = 0;
83  if (sourceIndex.isValid())
84  sourceRow = sourceIndex.row();
85  mUndoAction = new ActionMoveItem(mSourceParentId, mTargetParentId, sourceRow);
87 
88  gGraphContextManager->moveItem(mObject.id(), isDirectory, mTargetParentId, mTargetRow);
89 
90  return UserAction::exec();
91  }
92 }
UserActionFactory for ActionMoveItem.
UserAction * newAction() const
static ActionMoveItemFactory * sFactory
void addToHash(QCryptographicHash &cryptoHash) const override
QString tagname() const override
void writeToXml(QXmlStreamWriter &xmlOut) const override
bool exec() override
void readFromXml(QXmlStreamReader &xmlIn) override
ActionMoveItem(u32 tgtId=0, u32 srcId=0, int tgtRow=-1)
(Future) Base class for all tree models related to the details widget.
virtual BaseTreeItem * getParent() const
QModelIndex getIndexFromItem(BaseTreeItem *item) const
BaseTreeItem * getDirectory(u32 directoryId) const
BaseTreeItem * getContext(u32 contextId) const
ContextTreeModel * getContextTreeModel() const
bool moveItem(u32 itemId, bool isDirectory, u32 parentId, int row=-1)
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
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
quint32 u32
void addData(const char *data, int length)
bool isValid() const const
int row() const const
uint toUInt(bool *ok, int base) const const
QStringRef name() const const
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void writeTextElement(const QString &qualifiedName, const QString &text)