Changeset 91252 in vbox
- Timestamp:
- Sep 15, 2021 12:50:23 PM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.cpp
r91220 r91252 148 148 } 149 149 150 /* static */ 151 QString UIDiskEditorGroupBox::defaultExtension(const CMediumFormat &mediumFormatRef, KDeviceType enmDeviceType) 152 { 153 if (!mediumFormatRef.isNull()) 154 { 155 /* Load extension / device list: */ 156 QVector<QString> fileExtensions; 157 QVector<KDeviceType> deviceTypes; 158 CMediumFormat mediumFormat(mediumFormatRef); 159 mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes); 160 for (int i = 0; i < fileExtensions.size(); ++i) 161 if (deviceTypes[i] == enmDeviceType) 162 return fileExtensions[i].toLower(); 163 } 164 AssertMsgFailed(("Extension can't be NULL!\n")); 165 return QString(); 166 } 167 150 168 151 169 /********************************************************************************************************************************* … … 155 173 UIDiskFormatsGroupBox::UIDiskFormatsGroupBox(bool fExpertMode, KDeviceType enmDeviceType, QWidget *pParent /* = 0 */) 156 174 : UIDiskEditorGroupBox(fExpertMode, pParent) 175 , m_enmDeviceType(enmDeviceType) 157 176 , m_pFormatButtonGroup(0) 158 { 159 prepare(enmDeviceType); 177 , m_pMainLayout(0) 178 { 179 prepare(); 180 160 181 } 161 182 162 183 CMediumFormat UIDiskFormatsGroupBox::mediumFormat() const 163 184 { 164 return m_pFormatButtonGroup && m_pFormatButtonGroup->checkedButton() ? m_formats[m_pFormatButtonGroup->checkedId()] : CMediumFormat(); 185 return m_pFormatButtonGroup && 186 m_pFormatButtonGroup->checkedButton() ? m_formatList[m_pFormatButtonGroup->checkedId()].m_comFormat : CMediumFormat(); 165 187 } 166 188 167 189 void UIDiskFormatsGroupBox::setMediumFormat(const CMediumFormat &mediumFormat) 168 190 { 169 int iPosition = m_formats.indexOf(mediumFormat); 191 int iPosition = -1; 192 for (int i = 0; i < m_formatList.size(); ++i) 193 { 194 if (mediumFormat == m_formatList[i].m_comFormat) 195 iPosition = i; 196 } 170 197 if (iPosition >= 0) 171 198 { … … 180 207 } 181 208 182 void UIDiskFormatsGroupBox::prepare(KDeviceType enmDeviceType) 183 { 184 QVBoxLayout *pContainerLayout = new QVBoxLayout(this); 185 186 m_pFormatButtonGroup = new QButtonGroup(this); 187 AssertReturnVoid(m_pFormatButtonGroup); 209 void UIDiskFormatsGroupBox::prepare() 210 { 211 m_pMainLayout = new QVBoxLayout(this); 212 populateFormats(); 213 createFormatWidgets(); 214 retranslateUi(); 215 } 216 217 void UIDiskFormatsGroupBox::populateFormats(){ 188 218 /* Enumerate medium formats in special order: */ 189 219 CSystemProperties properties = uiCommon().virtualBox().GetSystemProperties(); … … 209 239 /* Create buttons for VDI, preferred and others: */ 210 240 foreach (const QString &strId, vdi.keys()) 211 addFormat Button(pContainerLayout, vdi.value(strId), enmDeviceType, true);241 addFormat(vdi.value(strId), true); 212 242 foreach (const QString &strId, preferred.keys()) 213 addFormat Button(pContainerLayout, preferred.value(strId), enmDeviceType, true);214 215 if (m_fExpertMode || enmDeviceType == KDeviceType_DVD ||enmDeviceType == KDeviceType_Floppy)243 addFormat(preferred.value(strId), true); 244 245 if (m_fExpertMode || m_enmDeviceType == KDeviceType_DVD || m_enmDeviceType == KDeviceType_Floppy) 216 246 { 217 247 foreach (const QString &strId, others.keys()) 218 addFormatButton(pContainerLayout, others.value(strId), enmDeviceType); 219 } 220 221 /* Select VDI: */ 222 if (!m_pFormatButtonGroup->buttons().isEmpty()) 223 { 224 m_pFormatButtonGroup->button(0)->click(); 225 m_pFormatButtonGroup->button(0)->setFocus(); 226 } 227 228 connect(m_pFormatButtonGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), 229 this, &UIDiskFormatsGroupBox::sigMediumFormatChanged); 230 231 retranslateUi(); 248 addFormat(others.value(strId)); 249 } 232 250 } 233 251 … … 241 259 { 242 260 QAbstractButton *pButton = buttons[i]; 243 UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_format Names[m_pFormatButtonGroup->id(pButton)]);261 UIMediumFormat enmFormat = gpConverter->fromInternalString<UIMediumFormat>(m_formatList[m_pFormatButtonGroup->id(pButton)].m_strName); 244 262 pButton->setText(gpConverter->toString(enmFormat)); 245 263 } 246 264 } 247 265 248 void UIDiskFormatsGroupBox::addFormatButton(QVBoxLayout *pFormatLayout, CMediumFormat medFormat, 249 KDeviceType enmDeviceType, bool fPreferred /* = false */) 266 void UIDiskFormatsGroupBox::addFormat(CMediumFormat medFormat, bool fPreferred /* = false */) 250 267 { 251 268 /* Check that medium format supports creation: */ … … 264 281 QVector<KDeviceType> deviceTypes; 265 282 medFormat.DescribeFileExtensions(fileExtensions, deviceTypes); 266 if (!deviceTypes.contains( enmDeviceType))283 if (!deviceTypes.contains(m_enmDeviceType)) 267 284 return; 268 269 /* Create/add corresponding radio-button: */ 270 QRadioButton *pFormatButton = new QRadioButton; 271 AssertPtrReturnVoid(pFormatButton); 272 { 285 m_formatList << Format(medFormat, medFormat.GetName(), defaultExtension(medFormat, m_enmDeviceType), fPreferred); 286 } 287 288 const QStringList UIDiskFormatsGroupBox::formatExtensions() const 289 { 290 QStringList extensionList; 291 foreach (const Format &format, m_formatList) 292 extensionList << format.m_strExtension; 293 return extensionList; 294 } 295 296 void UIDiskFormatsGroupBox::createFormatWidgets() 297 { 298 AssertReturnVoid(m_pMainLayout); 299 AssertReturnVoid(!m_formatList.isEmpty()); 300 m_pFormatButtonGroup = new QButtonGroup(this); 301 AssertReturnVoid(m_pFormatButtonGroup); 302 303 for (int i = 0; i < m_formatList.size(); ++i) 304 { 305 QRadioButton *pFormatButton = new QRadioButton; 306 if (!pFormatButton) 307 continue; 308 273 309 /* Make the preferred button font bold: */ 274 if ( fPreferred && m_fExpertMode)310 if (m_formatList[i].m_fPreferred && m_fExpertMode) 275 311 { 276 312 QFont font = pFormatButton->font(); … … 278 314 pFormatButton->setFont(font); 279 315 } 280 pFormatLayout->addWidget(pFormatButton); 281 m_formats << medFormat; 282 m_formatNames << medFormat.GetName(); 283 m_pFormatButtonGroup->addButton(pFormatButton, m_formatNames.size() - 1); 284 m_formatExtensions << defaultExtension(medFormat, enmDeviceType); 285 } 286 } 287 288 const QStringList UIDiskFormatsGroupBox::formatExtensions() const 289 { 290 return m_formatExtensions; 291 } 292 293 /* static */ 294 QString UIDiskFormatsGroupBox::defaultExtension(const CMediumFormat &mediumFormatRef, KDeviceType enmDeviceType) 295 { 296 if (!mediumFormatRef.isNull()) 297 { 298 /* Load extension / device list: */ 299 QVector<QString> fileExtensions; 300 QVector<KDeviceType> deviceTypes; 301 CMediumFormat mediumFormat(mediumFormatRef); 302 mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes); 303 for (int i = 0; i < fileExtensions.size(); ++i) 304 if (deviceTypes[i] == enmDeviceType) 305 return fileExtensions[i].toLower(); 306 } 307 AssertMsgFailed(("Extension can't be NULL!\n")); 308 return QString(); 309 } 310 311 316 m_pMainLayout->addWidget(pFormatButton); 317 m_pFormatButtonGroup->addButton(pFormatButton, i); 318 } 319 320 setMediumFormat(m_formatList[0].m_comFormat); 321 connect(m_pFormatButtonGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), 322 this, &UIDiskFormatsGroupBox::sigMediumFormatChanged); 323 } 312 324 /********************************************************************************************************************************* 313 325 * UIDiskVariantGroupBox implementation. * -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.h
r91223 r91252 25 25 #include <QIcon> 26 26 #include <QGroupBox> 27 #include <QVector> 27 28 28 29 /* Local includes: */ … … 64 65 static QString openFileDialogForDiskFile(const QString &strInitialPath, const CMediumFormat &comMediumFormat, 65 66 KDeviceType enmDeviceType, QWidget *pParent); 67 /** Attempts to find a file extention for the device type @p enmDeviceType within the extensions 68 * returned by CMediumFormat::DescribeFileExtensions(..). */ 69 static QString defaultExtension(const CMediumFormat &mediumFormatRef, KDeviceType enmDeviceType); 66 70 67 71 protected: … … 85 89 const CMediumFormat &VDIMediumFormat() const; 86 90 const QStringList formatExtensions() const; 87 /** Attempts to find a file extention for the device type @p enmDeviceType within the extensions88 * returned by CMediumFormat::DescribeFileExtensions(..). */89 static QString defaultExtension(const CMediumFormat &mediumFormatRef, KDeviceType enmDeviceType);90 91 91 92 private: 93 struct Format 94 { 95 CMediumFormat m_comFormat; 96 QString m_strName; 97 QString m_strExtension; 98 bool m_fPreferred; 99 Format(const CMediumFormat &comFormat, const QString &strName, 100 const QString &strExtension, bool fPreferred) 101 : m_comFormat(comFormat) 102 , m_strName(strName) 103 , m_strExtension(strExtension) 104 , m_fPreferred(fPreferred){} 105 }; 92 106 93 void prepare(KDeviceType enmDeviceType); 94 void addFormatButton(QVBoxLayout *pFormatLayout, CMediumFormat medFormat, KDeviceType enmDeviceType, bool fPreferred = false); 95 107 void prepare(); 108 void populateFormats(); 109 void addFormat(CMediumFormat medFormat, bool fPreferred = false); 110 void createFormatWidgets(); 96 111 virtual void retranslateUi() /* override final */; 97 112 98 QList<CMediumFormat> m_formats; 113 QVector<Format> m_formatList; 114 99 115 CMediumFormat m_comVDIMediumFormat; 100 QStringList m_formatNames;101 QStringList m_formatExtensions; 116 KDeviceType m_enmDeviceType; 117 102 118 QButtonGroup *m_pFormatButtonGroup; 119 QVBoxLayout *m_pMainLayout; 103 120 }; 104 121
Note:
See TracChangeset
for help on using the changeset viewer.