AronTreeWidgetItem.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QTreeWidget>
4 
6 
9 
11 
12 #include "Data.h"
13 
14 namespace armarx
15 {
16  // Internal derived QtTreeWidgetItem class. Contains additional information to compare its data agains aron types.
17  // It contains 3 columns: Key ; Value ; Type
18  // The key can only be edited if the parent object is a dict
19  class AronTreeWidgetItem : public QObject, public QTreeWidgetItem
20  {
21  Q_OBJECT
22  public:
23  AronTreeWidgetItem(bool editKey, bool editVal, QString key, aron::type::VariantPtr type);
24 
25  using QTreeWidgetItem::QTreeWidgetItem;
26 
27  static AronTreeWidgetItem* DynamicCast(QTreeWidgetItem*);
28  static AronTreeWidgetItem* DynamicCastAndCheck(QTreeWidgetItem*);
29 
31  // if editing the first column should be allowed
32  const bool col0Editable = false;
33  // if editing the second column should be allowed
34  const bool col1Editable = false;
35 
36  bool isValueErrorneous();
37  // marks the gui in a specific color. Also stores if there is currently an error.
38  // the only way to reset the color back to normal is with resetError() (error is sticky)
39  void setValueErrorState(bool isErrorSource, bool isTransitiveError);
40  void setKeyErrorState(bool hasError);
41  // reset error storage that influences coloring for this and all children
42  void resetError();
43 
44  // Checks if the children of a dict are unique
45  // should not be called on other types! (does nothing then)
47 
48  // main logic on changes. Gets called from the onTreeWidgetItemChanged() slot in AronTreeWidgetController.
49  // (This class cannot directly consume this signal, at least I did not find a nice way...)
50  void onUserChange(int changedColumn);
51 
52  private:
53  // because the editable keyword counts for all columns, it is possible to TAB into uneditable keys.
54  // We do not want those to change, so just change them back once they finished editing.
55  void preventIllegalKeyChange();
56 
57  bool itemValueError = false;
58  bool transitiveValueError = false;
59  bool keyValueError = false;
60  // hacky storage of previous key value for items that usually should not be editable.
61  // Problem: Dict-keys are editable, one can tab from that to any other value field and edit it.
62  // Fix: Once the change is commited, the AronTreeWidgetController notices the change and checks if it was allowed.
63  QString unchangeableKey = "";
64  };
65 } // namespace armarx
armarx::AronTreeWidgetItem::checkKeyValidityOfChildren
void checkKeyValidityOfChildren()
Definition: AronTreeWidgetItem.cpp:91
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::AronTreeWidgetItem::resetError
void resetError()
Definition: AronTreeWidgetItem.cpp:76
armarx::AronTreeWidgetItem
Definition: AronTreeWidgetItem.h:19
Data.h
armarx::AronTreeWidgetItem::col1Editable
const bool col1Editable
Definition: AronTreeWidgetItem.h:34
ArmarXGuiPlugin.h
armarx::AronTreeWidgetItem::setKeyErrorState
void setKeyErrorState(bool hasError)
Definition: AronTreeWidgetItem.cpp:64
Variant.h
ArmarXComponentWidgetController.h
armarx::AronTreeWidgetItem::DynamicCastAndCheck
static AronTreeWidgetItem * DynamicCastAndCheck(QTreeWidgetItem *)
Definition: AronTreeWidgetItem.cpp:21
armarx::AronTreeWidgetItem::col0Editable
const bool col0Editable
Definition: AronTreeWidgetItem.h:32
armarx::AronTreeWidgetItem::setValueErrorState
void setValueErrorState(bool isErrorSource, bool isTransitiveError)
Definition: AronTreeWidgetItem.cpp:39
armarx::AronTreeWidgetItem::DynamicCast
static AronTreeWidgetItem * DynamicCast(QTreeWidgetItem *)
Definition: AronTreeWidgetItem.cpp:15
armarx::AronTreeWidgetItem::isValueErrorneous
bool isValueErrorneous()
Definition: AronTreeWidgetItem.cpp:33
armarx::AronTreeWidgetItem::onUserChange
void onUserChange(int changedColumn)
Definition: AronTreeWidgetItem.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::AronTreeWidgetItem::aronType
aron::type::VariantPtr aronType
Definition: AronTreeWidgetItem.h:30
armarx::AronTreeWidgetItem::AronTreeWidgetItem
AronTreeWidgetItem(bool editKey, bool editVal, QString key, aron::type::VariantPtr type)
Definition: AronTreeWidgetItem.cpp:187
ImportExportComponent.h