VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
uiPropertiesTable.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2013 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 
8 
9 #pragma once
10 
13 #include "vrfutil/rwInt.h"
14 #include "vrfutil/rwReal.h"
15 #include "vrfutil/rwString.h"
16 #include "vrfutil/rwProperties.h"
17 
18 #include <QTableWidget>
19 #include <QHeaderView>
20 #include <QKeyEvent>
21 #include <QItemDelegate>
22 #include <QComboBox>
23 
26 class QTableWidgetItem;
27 class QHBoxLayout;
28 class QPushButton;
29 class QVBoxLayout;
30 class DtRwPropertiesList;
31 
35 {
36 public:
37  DtUiPropertiesTableWidget(QWidget * parent = 0) : QTableWidget(parent) {}
39 
40  virtual QSize sizeHint() const;
41  virtual void accept();
42 };
43 
45 {
46 public:
47  DtUiTableWidgetItem() : myOriginalValue(0), myModifiedValue(0), myIsKey(false), myIsReadOnly(false), myOwnsValues(false), myIsPropertyValue(true) {};
48 
49  virtual ~DtUiTableWidgetItem() { if (myOwnsValues) { delete myOriginalValue; delete myModifiedValue; } };
50 
51  void setOwnsValues(bool b) { myOwnsValues = b; };
52  void setOriginalValue(const DtReaderWriter* rw) { if (myOwnsValues) delete myOriginalValue; myOriginalValue = rw; };
53  void setModifiedValue(const DtReaderWriter* rw) { if (myOwnsValues) delete myModifiedValue; myModifiedValue = rw; };
54  void setIsPropertyValue(bool b) { myIsPropertyValue = b; };
55 
56  bool isInt() const { return dynamic_cast<const DtRwInt*>(myOriginalValue) != 0; };
57  bool isReal() const { return dynamic_cast<const DtRwReal*>(myOriginalValue) != 0; };
58  void setIsKey(bool b) { myIsKey = b; };
59  bool isKey() const { return myIsKey; };
60 
61  virtual QVariant data(int role) const
62  {
63  if (role == Qt::BackgroundColorRole)
64  {
65  if (flags() & Qt::ItemIsEditable)
66  {
67  return QTableWidgetItem::data(role);
68  }
69  else
70  {
71  return QColor(Qt::lightGray);
72  }
73  }
74  else if (role == Qt::FontRole)
75  {
76  QFont f = qvariant_cast<QFont>(QTableWidgetItem::data(Qt::FontRole));
77 
78  bool same = true;
79 
80  if (!myOriginalValue && myModifiedValue)
81  {
82  same = false;
83  }
84  else if (myIsKey)
85  {
86  same = (myOriginalValue->name() == myModifiedValue->name());
87  }
88  else if (myOriginalValue && myModifiedValue)
89  {
90  if (myIsPropertyValue)
91  {
92  same = DtRwProperties::propertyFactory()->compareReaderWriter(myOriginalValue, myModifiedValue);
93  }
94  else
95  {
96  same = DtRwProperties::factory()->compareReaderWriter(myOriginalValue, myModifiedValue);
97  }
98  }
99 
100  f.setBold(!same);
101 
102  return f;
103  }
104 
105  return QTableWidgetItem::data(role);
106  }
107 
108  void setReadOnly(bool b) { if (b) setFlags((Qt::ItemFlags)(flags() & ~Qt::ItemIsEditable)); else setFlags((Qt::ItemFlags)(flags() | Qt::ItemIsEditable)); };
109  const DtReaderWriter* originalValue() const { return myOriginalValue; }
110  const DtReaderWriter* modifiedValue() const { return myModifiedValue; }
111 
112 protected:
113  bool myIsKey;
119 };
120 
122 {
123 public:
124  DtUiTableWidgetItemDelegate(QObject* p, bool b) : QItemDelegate(p), myRowsAsColumns(b), myTable(dynamic_cast<QTableWidget*>(p)) {};
125 
126 protected:
127  virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
128  const QModelIndex &index) const;
129 
130 protected:
132  QIntValidator myIntValidator;
133  QDoubleValidator myDoubleValidator;
135 };
136 
138 {
139 public:
142 
143  void setTableWidgetItem(DtUiTableWidgetItem* i) { myTableWidgetItem = i; };
144  DtUiTableWidgetItem* tableWidgetItem() const { return myTableWidgetItem; };
145 
146 protected:
147  virtual void paintEvent(QPaintEvent *);
148 
149 protected:
151 };
152 
154 {
155  Q_OBJECT
156 
157 public:
160 
162  virtual ~DtUiPropertiesTable();
163 
165 
166  virtual void setEnabled(bool);
167 
168 protected:
169  virtual void setFromParameters(const std::vector<DtReaderWriter*>& parentRw);
170 
172  virtual void createControls(QWidget* widget);
173  virtual void processUiEvent(const DtUiElementEvent& e);
174 
175  virtual void columnHeadersFrom(const DtPropertyInterface* prototype, QStringList& columns) const;
176  virtual QString columnTitleFor(const QString&) const;
177  virtual void fillInAndMapRwItemToTableItems(int row, int& colStart, DtReaderWriter*);
178 
179  virtual const DtReaderWriter* readerWriterFromPrototype(const DtReaderWriter* prototype, int col) const;
180 
181  virtual void flatten(const DtReaderWriter* prototype, std::vector<const DtReaderWriter*>& list) const;
182  virtual void tableItemCreated(DtUiTableWidgetItem*, int row, int col);
183 
184  virtual void itemRemoved(DtUiTableWidgetItem*);
185  virtual void updateEnableStatus();
186 
187  virtual QStringList convertToTitles(const QStringList& cols) const;
188 
189 protected slots:
190  virtual void itemChanged(QTableWidgetItem*);
191  virtual void addRow();
192  virtual void removeRow();
193  virtual void itemSelectionChanged();
194  virtual void valueComboChanged();
195 
196 public:
200  QVBoxLayout* myLayout;
201  QHBoxLayout* myButtonLayout;
202 
203 protected:
204  typedef std::map<DtUiTableWidgetItem*, DtReaderWriter*> TableWidgetItemMap;
208 };

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)