Changeset View
Changeset View
Standalone View
Standalone View
plugins/filetemplates/templateoptionspage.cpp
Show All 37 Lines | |||||
38 | using namespace KDevelop; | 38 | using namespace KDevelop; | ||
39 | 39 | | |||
40 | class KDevelop::TemplateOptionsPagePrivate | 40 | class KDevelop::TemplateOptionsPagePrivate | ||
41 | { | 41 | { | ||
42 | public: | 42 | public: | ||
43 | QList<SourceFileTemplate::ConfigOption> entries; | 43 | QList<SourceFileTemplate::ConfigOption> entries; | ||
44 | QHash<QString, QWidget*> controls; | 44 | QHash<QString, QWidget*> controls; | ||
45 | QHash<QString, QByteArray> typeProperties; | 45 | QHash<QString, QByteArray> typeProperties; | ||
46 | QWidget *firstEditWidget; | ||||
46 | }; | 47 | }; | ||
47 | 48 | | |||
48 | TemplateOptionsPage::TemplateOptionsPage(QWidget* parent, Qt::WindowFlags f) | 49 | TemplateOptionsPage::TemplateOptionsPage(QWidget* parent, Qt::WindowFlags f) | ||
49 | : QWidget(parent, f) | 50 | : QWidget(parent, f) | ||
50 | , d(new TemplateOptionsPagePrivate) | 51 | , d(new TemplateOptionsPagePrivate) | ||
51 | { | 52 | { | ||
53 | d->firstEditWidget = nullptr; | ||||
54 | | ||||
52 | d->typeProperties.insert(QStringLiteral("String"), "text"); | 55 | d->typeProperties.insert(QStringLiteral("String"), "text"); | ||
53 | d->typeProperties.insert(QStringLiteral("Int"), "value"); | 56 | d->typeProperties.insert(QStringLiteral("Int"), "value"); | ||
54 | d->typeProperties.insert(QStringLiteral("Bool"), "checked"); | 57 | d->typeProperties.insert(QStringLiteral("Bool"), "checked"); | ||
55 | } | 58 | } | ||
56 | 59 | | |||
57 | TemplateOptionsPage::~TemplateOptionsPage() | 60 | TemplateOptionsPage::~TemplateOptionsPage() | ||
58 | { | 61 | { | ||
59 | delete d; | 62 | delete d; | ||
60 | } | 63 | } | ||
61 | 64 | | |||
62 | void TemplateOptionsPage::load(const SourceFileTemplate& fileTemplate, TemplateRenderer* renderer) | 65 | void TemplateOptionsPage::load(const SourceFileTemplate& fileTemplate, TemplateRenderer* renderer) | ||
63 | { | 66 | { | ||
64 | d->entries.clear(); | 67 | d->entries.clear(); | ||
68 | d->controls.clear(); | ||||
69 | d->firstEditWidget = nullptr; | ||||
65 | 70 | | |||
66 | QLayout* layout = new QVBoxLayout(); | 71 | QLayout* layout = new QVBoxLayout(); | ||
67 | QHash<QString, QList<SourceFileTemplate::ConfigOption> > options = fileTemplate.customOptions(renderer); | 72 | QHash<QString, QList<SourceFileTemplate::ConfigOption> > options = fileTemplate.customOptions(renderer); | ||
68 | QHash<QString, QList<SourceFileTemplate::ConfigOption> >::const_iterator it; | 73 | QHash<QString, QList<SourceFileTemplate::ConfigOption> >::const_iterator it; | ||
69 | 74 | | |||
70 | for (it = options.constBegin(); it != options.constEnd(); ++it) | 75 | for (it = options.constBegin(); it != options.constEnd(); ++it) | ||
71 | { | 76 | { | ||
72 | QGroupBox* box = new QGroupBox(this); | 77 | QGroupBox* box = new QGroupBox(this); | ||
Show All 36 Lines | 113 | { | |||
109 | qCDebug(PLUGIN_FILETEMPLATES) << "Unrecognized option type" << entry.type; | 114 | qCDebug(PLUGIN_FILETEMPLATES) << "Unrecognized option type" << entry.type; | ||
110 | } | 115 | } | ||
111 | if (control) | 116 | if (control) | ||
112 | { | 117 | { | ||
113 | const QString entryLabelText = i18n("%1:", entry.label); | 118 | const QString entryLabelText = i18n("%1:", entry.label); | ||
114 | QLabel* label = new QLabel(entryLabelText, box); | 119 | QLabel* label = new QLabel(entryLabelText, box); | ||
115 | formLayout->addRow(label, control); | 120 | formLayout->addRow(label, control); | ||
116 | d->controls.insert(entry.name, control); | 121 | d->controls.insert(entry.name, control); | ||
122 | if (d->firstEditWidget == nullptr) { | ||||
123 | d->firstEditWidget = control; | ||||
124 | } | ||||
117 | } | 125 | } | ||
118 | } | 126 | } | ||
119 | 127 | | |||
120 | box->setLayout(formLayout); | 128 | box->setLayout(formLayout); | ||
121 | layout->addWidget(box); | 129 | layout->addWidget(box); | ||
122 | } | 130 | } | ||
123 | setLayout(layout); | 131 | setLayout(layout); | ||
124 | } | 132 | } | ||
Show All 9 Lines | 139 | { | |||
134 | 142 | | |||
135 | values.insert(entry.name, d->controls[entry.name]->property(d->typeProperties[entry.type])); | 143 | values.insert(entry.name, d->controls[entry.name]->property(d->typeProperties[entry.type])); | ||
136 | } | 144 | } | ||
137 | 145 | | |||
138 | qCDebug(PLUGIN_FILETEMPLATES) << values.size() << d->entries.size(); | 146 | qCDebug(PLUGIN_FILETEMPLATES) << values.size() << d->entries.size(); | ||
139 | 147 | | |||
140 | return values; | 148 | return values; | ||
141 | } | 149 | } | ||
150 | | ||||
151 | void TemplateOptionsPage::setFocusToFirstEditWidget() | ||||
152 | { | ||||
153 | if (d->firstEditWidget) { | ||||
154 | d->firstEditWidget->setFocus(); | ||||
155 | } | ||||
156 | } |