51 QDesignerDialogGuiInterface *dlgui,
55 return dlgui->message(parent, QDesignerDialogGuiInterface::OtherMessage,
56 QMessageBox::Question, title, what,
57 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes;
77 QStringList existingProfileNames()
const;
78 void sortAndPopulateProfileCombo();
80 void updateDescriptionLabel();
82 QDesignerFormEditorInterface *m_core;
83 QComboBox *m_profileCombo;
84 QToolButton *m_addButton;
85 QToolButton *m_editButton;
86 QToolButton *m_deleteButton;
87 QLabel *m_descriptionLabel;
89 DeviceProfileList m_sortedProfiles;
91 QSet<QString> m_usedProfiles;
97 m_profileCombo(
new QComboBox),
98 m_addButton(
new QToolButton),
99 m_editButton(
new QToolButton),
100 m_deleteButton(
new QToolButton),
101 m_descriptionLabel(
new QLabel)
103 m_descriptionLabel->setMinimumHeight(80);
105 const QDesignerFormWindowManagerInterface *fwm = core->formWindowManager();
106 if (
const int fwCount = fwm->formWindowCount()) {
107 for (
int i = 0; i < fwCount; i++)
108 if (
const FormWindowBase *fwb = qobject_cast<
const FormWindowBase *>(fwm->formWindow(i))) {
109 const QString deviceProfileName = fwb->deviceProfileName();
110 if (!deviceProfileName.isEmpty())
111 m_usedProfiles.insert(deviceProfileName);
116void EmbeddedOptionsControlPrivate::init(EmbeddedOptionsControl *q)
119 QVBoxLayout *vLayout =
new QVBoxLayout;
120 QHBoxLayout *hLayout =
new QHBoxLayout;
121 m_profileCombo->setMinimumWidth(200);
122 m_profileCombo->setEditable(
false);
123 hLayout->addWidget(m_profileCombo);
124 m_profileCombo->addItem(EmbeddedOptionsControl::tr(
"None"));
125 EmbeddedOptionsControl::connect(m_profileCombo, &QComboBox::currentIndexChanged,
126 m_q, &EmbeddedOptionsControl::slotProfileIndexChanged);
128 m_addButton->setIcon(createIconSet(
"plus.png"_L1));
129 m_addButton->setToolTip(EmbeddedOptionsControl::tr(
"Add a profile"));
130 EmbeddedOptionsControl::connect(m_addButton, &QAbstractButton::clicked,
131 m_q, &EmbeddedOptionsControl::slotAdd);
132 hLayout->addWidget(m_addButton);
134 EmbeddedOptionsControl::connect(m_editButton, &QAbstractButton::clicked,
135 m_q, &EmbeddedOptionsControl::slotEdit);
136 m_editButton->setIcon(createIconSet(
"edit.png"_L1));
137 m_editButton->setToolTip(EmbeddedOptionsControl::tr(
"Edit the selected profile"));
138 hLayout->addWidget(m_editButton);
140 m_deleteButton->setIcon(createIconSet(
"minus.png"_L1));
141 m_deleteButton->setToolTip(EmbeddedOptionsControl::tr(
"Delete the selected profile"));
142 EmbeddedOptionsControl::connect(m_deleteButton, &QAbstractButton::clicked,
143 m_q, &EmbeddedOptionsControl::slotDelete);
144 hLayout->addWidget(m_deleteButton);
146 hLayout->addStretch();
147 vLayout->addLayout(hLayout);
148 vLayout->addWidget(m_descriptionLabel);
149 m_q->setLayout(vLayout);
160void EmbeddedOptionsControlPrivate::slotAdd()
162 DeviceProfileDialog dlg(m_core->dialogGui(), m_q);
163 dlg.setWindowTitle(EmbeddedOptionsControl::tr(
"Add Profile"));
165 DeviceProfile settings;
166 settings.fromSystem();
167 dlg.setDeviceProfile(settings);
169 const QStringList names = existingProfileNames();
170 const QString newNamePrefix = EmbeddedOptionsControl::tr(
"New profile");
171 QString newName = newNamePrefix;
172 for (
int i = 2; names.contains(newName); i++) {
173 newName = newNamePrefix;
174 newName += QString::number(i);
177 settings.setName(newName);
178 dlg.setDeviceProfile(settings);
179 if (dlg.showDialog(names)) {
180 const DeviceProfile newProfile = dlg.deviceProfile();
181 m_sortedProfiles.push_back(newProfile);
183 sortAndPopulateProfileCombo();
184 const int index = m_profileCombo->findText(newProfile.name());
185 m_profileCombo->setCurrentIndex(index);
190void EmbeddedOptionsControlPrivate::slotEdit()
192 const int index = m_profileCombo->currentIndex() - profileComboIndexOffset;
199 const DeviceProfile oldProfile = m_sortedProfiles.at(index);
200 const QString oldName = oldProfile.name();
201 QStringList names = existingProfileNames();
202 names.removeAll(oldName);
204 DeviceProfileDialog dlg(m_core->dialogGui(), m_q);
205 dlg.setWindowTitle(EmbeddedOptionsControl::tr(
"Edit Profile"));
206 dlg.setDeviceProfile(oldProfile);
207 if (dlg.showDialog(names)) {
208 const DeviceProfile newProfile = dlg.deviceProfile();
209 if (newProfile != oldProfile) {
211 m_sortedProfiles[index] = newProfile;
212 if (newProfile.name() != oldName) {
213 sortAndPopulateProfileCombo();
214 const int index = m_profileCombo->findText(newProfile.name());
215 m_profileCombo->setCurrentIndex(index);
217 updateDescriptionLabel();
224void EmbeddedOptionsControlPrivate::slotDelete()
226 const int index = m_profileCombo->currentIndex() - profileComboIndexOffset;
229 const QString name = m_sortedProfiles.at(index).name();
230 if (ask(m_q, m_core->dialogGui(),
231 EmbeddedOptionsControl::tr(
"Delete Profile"),
232 EmbeddedOptionsControl::tr(
"Would you like to delete the profile '%1'?").arg(name))) {
233 m_profileCombo->setCurrentIndex(0);
234 m_sortedProfiles.removeAt(index);
235 m_profileCombo->removeItem(index + profileComboIndexOffset);
251void EmbeddedOptionsControlPrivate::loadSettings()
253 const QDesignerSharedSettings settings(m_core);
254 m_sortedProfiles = settings.deviceProfiles();
255 sortAndPopulateProfileCombo();
257 const int settingsIndex = settings.currentDeviceProfileIndex();
258 const int profileIndex = settingsIndex >= 0 && settingsIndex < m_sortedProfiles.size() ? settingsIndex + profileComboIndexOffset : 0;
259 m_profileCombo->setCurrentIndex(profileIndex);
264void EmbeddedOptionsControlPrivate::saveSettings()
266 QDesignerSharedSettings settings(m_core);
267 settings.setDeviceProfiles(m_sortedProfiles);
269 settings.setCurrentDeviceProfileIndex(m_profileCombo->currentIndex() - profileComboIndexOffset);
380QWidget *EmbeddedOptionsPage::createPage(QWidget *parent)
382 QWidget *optionsWidget =
new QWidget(parent);
384 QVBoxLayout *optionsVLayout =
new QVBoxLayout();
387 QGroupBox *gb =
new QGroupBox(QCoreApplication::translate(
"EmbeddedOptionsPage",
"Device Profiles"));
388 QVBoxLayout *gbVLayout =
new QVBoxLayout();
389 m_embeddedOptionsControl =
new EmbeddedOptionsControl(m_core);
390 m_embeddedOptionsControl->loadSettings();
391 gbVLayout->addWidget(m_embeddedOptionsControl);
392 gb->setLayout(gbVLayout);
393 optionsVLayout->addWidget(gb);
395 optionsVLayout->addStretch(1);
398 QHBoxLayout *optionsHLayout =
new QHBoxLayout();
399 optionsHLayout->addLayout(optionsVLayout);
400 optionsHLayout->addStretch(1);
401 optionsWidget->setLayout(optionsHLayout);
402 return optionsWidget;
405void EmbeddedOptionsPage::apply()
407 if (!m_embeddedOptionsControl || !m_embeddedOptionsControl->isDirty())
410 m_embeddedOptionsControl->saveSettings();
411 if (FormWindowManager *fw = qobject_cast<qdesigner_internal::FormWindowManager *>(m_core->formWindowManager()))
412 fw->deviceProfilesChanged();