Changeset 78131 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Apr 15, 2019 7:20:20 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
r78130 r78131 48 48 49 49 50 /** QComboBox extension used as Port editor. */ 51 class ChoiceEditor : public QComboBox 52 { 53 Q_OBJECT; 54 Q_PROPERTY(ChoiceData choice READ choice WRITE setChoice USER true); 55 56 public: 57 58 /** Constructs Port-editor passing @a pParent to the base-class. */ 59 ChoiceEditor(QWidget *pParent = 0) 60 : QComboBox(pParent) {} 61 62 private: 63 64 /** Defines the @a choice. */ 65 void setChoice(ChoiceData choice) 66 { 67 addItems(choice.choices().toList()); 68 setCurrentIndex(choice.selectedChoice()); 69 } 70 71 /** Returns the choice. */ 72 ChoiceData choice() const 73 { 74 QVector<QString> choices(count()); 75 for (int i = 0; i < count(); ++i) 76 choices[i] = itemText(i); 77 return ChoiceData(choices, currentIndex()); 78 } 79 }; 80 81 50 82 /** QITableViewCell extension used as Form Editor table-view cell. */ 51 83 class UIFormEditorCell : public QITableViewCell … … 87 119 /** Returns the row value as string. */ 88 120 QString valueToString() const; 121 122 /** Returns value cast to bool. */ 123 bool toBool() const; 124 125 /** Returns value cast to string. */ 126 QString toString() const; 127 128 /** Returns value cast to choice. */ 129 ChoiceData toChoice() const; 89 130 90 131 protected: … … 215 256 { 216 257 return m_cells.at(UIFormEditorDataType_Value)->text(); 258 } 259 260 bool UIFormEditorRow::toBool() const 261 { 262 AssertReturn(valueType() == KFormValueType_Boolean, false); 263 CBooleanFormValue comValue(m_comValue); 264 return comValue.GetSelected(); 265 } 266 267 QString UIFormEditorRow::toString() const 268 { 269 AssertReturn(valueType() == KFormValueType_String, QString()); 270 CStringFormValue comValue(m_comValue); 271 return comValue.GetString(); 272 } 273 274 ChoiceData UIFormEditorRow::toChoice() const 275 { 276 AssertReturn(valueType() == KFormValueType_Choice, ChoiceData()); 277 CChoiceFormValue comValue(m_comValue); 278 return ChoiceData(comValue.GetValues(), comValue.GetSelectedIndex()); 217 279 } 218 280 … … 380 442 switch (iRole) 381 443 { 444 /* Checkstate role: */ 445 case Qt::CheckStateRole: 446 { 447 /* Switch for different columns: */ 448 switch (index.column()) 449 { 450 case UIFormEditorDataType_Value: 451 return m_dataList[index.row()]->valueType() == KFormValueType_Boolean 452 ? m_dataList[index.row()]->toBool() 453 ? Qt::Checked 454 : Qt::Unchecked 455 : QVariant(); 456 default: 457 return QVariant(); 458 } 459 } 382 460 /* Display role: */ 383 461 case Qt::DisplayRole: … … 396 474 } 397 475 } 476 /* Edit role: */ 477 case Qt::EditRole: 478 { 479 /* Switch for different columns: */ 480 switch (index.column()) 481 { 482 case UIFormEditorDataType_Value: 483 { 484 switch (m_dataList[index.row()]->valueType()) 485 { 486 case KFormValueType_String: 487 return QVariant::fromValue(m_dataList[index.row()]->toString()); 488 case KFormValueType_Choice: 489 return QVariant::fromValue(m_dataList[index.row()]->toChoice()); 490 default: 491 return QVariant(); 492 } 493 } 494 default: 495 return QVariant(); 496 } 497 } 398 498 /* Alignment role: */ 399 499 case Qt::TextAlignmentRole: … … 485 585 m_pTableView->setModel(m_pTableModel); 486 586 587 /* We certainly have abstract item delegate: */ 588 QAbstractItemDelegate *pAbstractItemDelegate = m_pTableView->itemDelegate(); 589 if (pAbstractItemDelegate) 590 { 591 /* But is this also styled item delegate? */ 592 QStyledItemDelegate *pStyledItemDelegate = qobject_cast<QStyledItemDelegate*>(pAbstractItemDelegate); 593 if (pStyledItemDelegate) 594 { 595 /* Create new item editor factory: */ 596 QItemEditorFactory *pNewItemEditorFactory = new QItemEditorFactory; 597 if (pNewItemEditorFactory) 598 { 599 /* Register ChoiceEditor as the ChoiceData editor: */ 600 int iChoiceId = qRegisterMetaType<ChoiceData>(); 601 QStandardItemEditorCreator<ChoiceEditor> *pChoiceEditorItemCreator = new QStandardItemEditorCreator<ChoiceEditor>(); 602 pNewItemEditorFactory->registerEditor((QVariant::Type)iChoiceId, pChoiceEditorItemCreator); 603 604 /* Set newly created item editor factory for table delegate: */ 605 pStyledItemDelegate->setItemEditorFactory(pNewItemEditorFactory); 606 } 607 } 608 } 609 487 610 /* Add into layout: */ 488 611 pLayout->addWidget(m_pTableView); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.h
r78129 r78131 31 31 32 32 33 /** Class used to hold choice data. */ 34 class ChoiceData 35 { 36 public: 37 38 /** Constructs null choice data. */ 39 ChoiceData() {} 40 /** Constructs choice data on the basis of passed @a choices and @a iSelectedChoice. */ 41 ChoiceData(const QVector<QString> &choices, int iSelectedChoice) 42 : m_choices(choices), m_iSelectedChoice(iSelectedChoice) {} 43 44 /** Returns choice list. */ 45 QVector<QString> choices() const { return m_choices; } 46 /** Returns current selected choice. */ 47 int selectedChoice() const { return m_iSelectedChoice; } 48 49 private: 50 51 /** Holds choice list. */ 52 QVector<QString> m_choices; 53 /** Holds current selected choice. */ 54 int m_iSelectedChoice; 55 }; 56 Q_DECLARE_METATYPE(ChoiceData); 57 58 33 59 /** QWidget subclass representing model/view Form Editor widget. */ 34 60 class UIFormEditorWidget : public QWidget
Note:
See TracChangeset
for help on using the changeset viewer.