- Timestamp:
- Apr 15, 2019 6:46:32 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp
r78128 r78129 35 35 #include "CVirtualSystemDescriptionForm.h" 36 36 37 /* VirtualBox interface declarations: */ 38 #include <VBox/com/VirtualBox.h> 39 40 41 /** Form Editor data types. */ 42 enum UIFormEditorDataType 43 { 44 UIFormEditorDataType_Name, 45 UIFormEditorDataType_Value, 46 UIFormEditorDataType_Max 47 }; 48 49 50 /** QITableViewCell extension used as Form Editor table-view cell. */ 51 class UIFormEditorCell : public QITableViewCell 52 { 53 Q_OBJECT; 54 55 public: 56 57 /** Constructs table cell on the basis of certain @a strText, passing @a pParent to the base-class. */ 58 UIFormEditorCell(QITableViewRow *pParent, const QString &strText); 59 60 /** Returns the cell text. */ 61 virtual QString text() const /* override */ { return m_strText; } 62 63 private: 64 65 /** Holds the cell text. */ 66 QString m_strText; 67 }; 68 69 70 /** QITableViewRow extension used as Form Editor table-view row. */ 71 class UIFormEditorRow : public QITableViewRow 72 { 73 Q_OBJECT; 74 75 public: 76 77 /** Constructs table row on the basis of certain @a comValue, passing @a pParent to the base-class. */ 78 UIFormEditorRow(QITableView *pParent, const CFormValue &comValue); 79 /** Destructs table row. */ 80 virtual ~UIFormEditorRow() /* override */; 81 82 /** Returns value type. */ 83 KFormValueType valueType() const { return m_enmValueType; } 84 85 protected: 86 87 /** Returns the number of children. */ 88 virtual int childCount() const /* override */; 89 /** Returns the child item with @a iIndex. */ 90 virtual QITableViewCell *childItem(int iIndex) const /* override */; 91 92 private: 93 94 /** Prepares all. */ 95 void prepare(); 96 /** Cleanups all. */ 97 void cleanup(); 98 99 /** Holds the row value. */ 100 CFormValue m_comValue; 101 102 /** Holds the value type. */ 103 KFormValueType m_enmValueType; 104 105 /** Holds the cell instances. */ 106 QVector<UIFormEditorCell*> m_cells; 107 }; 108 109 110 /** QAbstractTableModel subclass used as Form Editor data model. */ 111 class UIFormEditorModel : public QAbstractTableModel 112 { 113 Q_OBJECT; 114 115 public: 116 117 /** Constructs Form Editor model passing @a pParent to the base-class. */ 118 UIFormEditorModel(QITableView *pParent); 119 /** Destructs Port Forwarding model. */ 120 virtual ~UIFormEditorModel() /* override */; 121 122 /** Defines form @a values. */ 123 void setFormValues(const CFormValueVector &values); 124 125 /** Returns the number of children. */ 126 int childCount() const; 127 /** Returns the child item with @a iIndex. */ 128 QITableViewRow *childItem(int iIndex) const; 129 130 /** Returns flags for item with certain @a index. */ 131 Qt::ItemFlags flags(const QModelIndex &index) const; 132 133 /** Returns row count of certain @a parent. */ 134 int rowCount(const QModelIndex &parent = QModelIndex()) const; 135 136 /** Returns column count of certain @a parent. */ 137 int columnCount(const QModelIndex &parent = QModelIndex()) const; 138 139 /** Returns header data for @a iSection, @a enmOrientation and @a iRole specified. */ 140 QVariant headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const; 141 142 /** Defines the @a iRole data for item with @a index as @a value. */ 143 bool setData(const QModelIndex &index, const QVariant &value, int iRole = Qt::EditRole); 144 /** Returns the @a iRole data for item with @a index. */ 145 QVariant data(const QModelIndex &index, int iRole) const; 146 147 private: 148 149 /** Return the parent table-view reference. */ 150 QITableView *parentTable() const; 151 152 /** Holds the Form Editor row list. */ 153 QList<UIFormEditorRow*> m_dataList; 154 }; 155 37 156 38 157 /** QITableView extension used as Form Editor table-view. */ … … 56 175 57 176 /********************************************************************************************************************************* 177 * Class UIFormEditorCell implementation. * 178 *********************************************************************************************************************************/ 179 180 UIFormEditorCell::UIFormEditorCell(QITableViewRow *pParent, const QString &strText) 181 : QITableViewCell(pParent) 182 , m_strText(strText) 183 { 184 } 185 186 187 /********************************************************************************************************************************* 188 * Class UIFormEditorRow implementation. * 189 *********************************************************************************************************************************/ 190 191 UIFormEditorRow::UIFormEditorRow(QITableView *pParent, const CFormValue &comValue) 192 : QITableViewRow(pParent) 193 , m_comValue(comValue) 194 , m_enmValueType(KFormValueType_Max) 195 { 196 prepare(); 197 } 198 199 UIFormEditorRow::~UIFormEditorRow() 200 { 201 cleanup(); 202 } 203 204 int UIFormEditorRow::childCount() const 205 { 206 /* Return cell count: */ 207 return UIFormEditorDataType_Max; 208 } 209 210 QITableViewCell *UIFormEditorRow::childItem(int iIndex) const 211 { 212 /* Make sure index within the bounds: */ 213 AssertReturn(iIndex >= 0 && iIndex < m_cells.size(), 0); 214 /* Return corresponding cell: */ 215 return m_cells.at(iIndex); 216 } 217 218 void UIFormEditorRow::prepare() 219 { 220 /* Cache value type: */ 221 m_enmValueType = m_comValue.GetType(); 222 223 /* Create cells on the basis of variables we have: */ 224 m_cells.resize(UIFormEditorDataType_Max); 225 m_cells[UIFormEditorDataType_Name] = new UIFormEditorCell(this, m_comValue.GetLabel()); 226 switch (m_enmValueType) 227 { 228 case KFormValueType_Boolean: 229 { 230 CBooleanFormValue comValue(m_comValue); 231 m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, comValue.GetSelected() ? "True" : "False"); 232 break; 233 } 234 case KFormValueType_String: 235 { 236 CStringFormValue comValue(m_comValue); 237 m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, comValue.GetString()); 238 break; 239 } 240 case KFormValueType_Choice: 241 { 242 CChoiceFormValue comValue(m_comValue); 243 const QVector<QString> values = comValue.GetValues(); 244 m_cells[UIFormEditorDataType_Value] = new UIFormEditorCell(this, values.at(comValue.GetSelectedIndex())); 245 break; 246 } 247 default: 248 break; 249 } 250 } 251 252 void UIFormEditorRow::cleanup() 253 { 254 /* Destroy cells: */ 255 qDeleteAll(m_cells); 256 m_cells.clear(); 257 } 258 259 260 /********************************************************************************************************************************* 261 * Class UIFormEditorModel implementation. * 262 *********************************************************************************************************************************/ 263 264 UIFormEditorModel::UIFormEditorModel(QITableView *pParent) 265 : QAbstractTableModel(pParent) 266 { 267 } 268 269 UIFormEditorModel::~UIFormEditorModel() 270 { 271 /* Delete the cached data: */ 272 qDeleteAll(m_dataList); 273 m_dataList.clear(); 274 } 275 276 void UIFormEditorModel::setFormValues(const CFormValueVector &values) 277 { 278 /* Delete old lines: */ 279 beginRemoveRows(QModelIndex(), 0, m_dataList.size()); 280 qDeleteAll(m_dataList); 281 m_dataList.clear(); 282 endRemoveRows(); 283 284 /* Add new lines: */ 285 beginInsertRows(QModelIndex(), 0, values.size()); 286 foreach (const CFormValue &comValue, values) 287 m_dataList << new UIFormEditorRow(parentTable(), comValue); 288 endInsertRows(); 289 } 290 291 int UIFormEditorModel::childCount() const 292 { 293 return rowCount(); 294 } 295 296 QITableViewRow *UIFormEditorModel::childItem(int iIndex) const 297 { 298 /* Make sure index within the bounds: */ 299 AssertReturn(iIndex >= 0 && iIndex < m_dataList.size(), 0); 300 /* Return corresponding row: */ 301 return m_dataList[iIndex]; 302 } 303 304 Qt::ItemFlags UIFormEditorModel::flags(const QModelIndex &index) const 305 { 306 /* Check index validness: */ 307 if (!index.isValid()) 308 return Qt::NoItemFlags; 309 /* Return wrong value: */ 310 return Qt::NoItemFlags; 311 } 312 313 int UIFormEditorModel::rowCount(const QModelIndex &) const 314 { 315 return m_dataList.size(); 316 } 317 318 int UIFormEditorModel::columnCount(const QModelIndex &) const 319 { 320 return UIFormEditorDataType_Max; 321 } 322 323 QVariant UIFormEditorModel::headerData(int iSection, Qt::Orientation enmOrientation, int iRole) const 324 { 325 Q_UNUSED(iSection); 326 Q_UNUSED(enmOrientation); 327 Q_UNUSED(iRole); 328 329 /* Return wrong value: */ 330 return QVariant(); 331 } 332 333 bool UIFormEditorModel::setData(const QModelIndex &index, const QVariant &value, int iRole /* = Qt::EditRole */) 334 { 335 Q_UNUSED(value); 336 337 /* Check index validness: */ 338 if (!index.isValid() || iRole != Qt::EditRole) 339 return false; 340 /* Return wrong value: */ 341 return false; 342 } 343 344 QVariant UIFormEditorModel::data(const QModelIndex &index, int iRole) const 345 { 346 Q_UNUSED(iRole); 347 348 /* Check index validness: */ 349 if (!index.isValid()) 350 return QVariant(); 351 /* Return wrong value: */ 352 return QVariant(); 353 } 354 355 QITableView *UIFormEditorModel::parentTable() const 356 { 357 return qobject_cast<QITableView*>(parent()); 358 } 359 360 361 /********************************************************************************************************************************* 58 362 * Class UIFormEditorView implementation. * 59 363 *********************************************************************************************************************************/ … … 65 369 int UIFormEditorView::childCount() const 66 370 { 67 /* No model => no children: */ 68 return 0; 371 /* Redirect request to model: */ 372 AssertPtrReturn(model(), 0); 373 return qobject_cast<UIFormEditorModel*>(model())->childCount(); 69 374 } 70 375 71 376 QITableViewRow *UIFormEditorView::childItem(int iIndex) const 72 377 { 73 Q_UNUSED(iIndex); 74 75 /* No model => no children: */ 76 return 0; 378 /* Redirect request to model: */ 379 AssertPtrReturn(model(), 0); 380 return qobject_cast<UIFormEditorModel*>(model())->childItem(iIndex); 77 381 } 78 382 … … 85 389 : QWidget(pParent) 86 390 , m_pTableView(0) 391 , m_pTableModel(0) 87 392 { 88 393 prepare(); 394 } 395 396 void UIFormEditorWidget::setVirtualSystemDescriptionForm(const CVirtualSystemDescriptionForm &comForm) 397 { 398 AssertPtrReturnVoid(m_pTableModel); 399 /// @todo add some check.. 400 m_pTableModel->setFormValues(comForm.GetValues()); 89 401 } 90 402 … … 104 416 m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection); 105 417 418 /* Create model: */ 419 m_pTableModel = new UIFormEditorModel(m_pTableView); 420 if (m_pTableModel) 421 m_pTableView->setModel(m_pTableModel); 422 106 423 /* Add into layout: */ 107 424 pLayout->addWidget(m_pTableView); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.h
r78128 r78129 26 26 27 27 /* Forward declarations: */ 28 class UIFormEditorModel; 28 29 class UIFormEditorView; 30 class CVirtualSystemDescriptionForm; 29 31 30 32 … … 39 41 UIFormEditorWidget(QWidget *pParent = 0); 40 42 43 /** Defines virtual system description @a comForm to be edited. */ 44 void setVirtualSystemDescriptionForm(const CVirtualSystemDescriptionForm &comForm); 45 41 46 private: 42 47 … … 46 51 /** Holds the table-view instance. */ 47 52 UIFormEditorView *m_pTableView; 53 /** Holds the table-model instance. */ 54 UIFormEditorModel *m_pTableModel; 48 55 }; 49 56
Note:
See TracChangeset
for help on using the changeset viewer.