Changeset View
Changeset View
Standalone View
Standalone View
src/formeditor/commands.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
108 | class Q_DECL_HIDDEN PropertyCommand::Private | 108 | class Q_DECL_HIDDEN PropertyCommand::Private | ||
109 | { | 109 | { | ||
110 | public: | 110 | public: | ||
111 | Private() | 111 | Private() | ||
112 | : uniqueId(0) | 112 | : uniqueId(0) | ||
113 | { | 113 | { | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | bool thisSingleWidgetSelected() const | ||||
117 | { | ||||
118 | const QWidget *selected = form->selectedWidget(); | ||||
119 | return selected | ||||
120 | && oldValues.count() == 1 | ||||
121 | && oldValues.contains(selected->objectName().toLatin1()); | ||||
122 | } | ||||
123 | | ||||
116 | Form *form; | 124 | Form *form; | ||
117 | QVariant value; | 125 | QVariant value; | ||
118 | QHash<QByteArray, QVariant> oldValues; //!< (widget_name -> value) hash | 126 | QHash<QByteArray, QVariant> oldValues; //!< (widget_name -> value) hash | ||
119 | QByteArray propertyName; | 127 | QByteArray propertyName; | ||
120 | int uniqueId; | 128 | int uniqueId; | ||
121 | }; | 129 | }; | ||
122 | } | 130 | } | ||
123 | 131 | | |||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | |||||
190 | 198 | | |||
191 | void PropertyCommand::setUniqueId(int id) | 199 | void PropertyCommand::setUniqueId(int id) | ||
192 | { | 200 | { | ||
193 | d->uniqueId = id; | 201 | d->uniqueId = id; | ||
194 | } | 202 | } | ||
195 | 203 | | |||
196 | void PropertyCommand::execute() | 204 | void PropertyCommand::execute() | ||
197 | { | 205 | { | ||
198 | QWidget *selected = d->form->selectedWidget(); | | |||
199 | bool reSelectWidgets = true; | | |||
200 | if (selected | | |||
201 | && d->oldValues.count() == 1 | | |||
202 | && d->oldValues.contains(selected->objectName().toLatin1()) ) | | |||
203 | { | | |||
204 | // do not reselect widget; this e.g. avoids removing resize handles | 206 | // do not reselect widget; this e.g. avoids removing resize handles | ||
205 | reSelectWidgets = false; | 207 | const bool reSelectWidgets = !d->thisSingleWidgetSelected(); | ||
206 | } | | |||
207 | | ||||
208 | if (reSelectWidgets) { | 208 | if (reSelectWidgets) { | ||
209 | d->form->selectFormWidget(); | 209 | d->form->selectFormWidget(); | ||
210 | } | 210 | } | ||
211 | 211 | | |||
212 | d->form->setUndoing(true); | 212 | d->form->setUndoing(true); | ||
213 | 213 | | |||
214 | if (reSelectWidgets) { | 214 | if (reSelectWidgets) { | ||
215 | d->form->selectWidgets(d->oldValues.keys(), Form::ReplacePreviousSelection); | 215 | d->form->selectWidgets(d->oldValues.keys(), Form::ReplacePreviousSelection); | ||
Show All 14 Lines | 221 | { | |||
230 | } | 230 | } | ||
231 | } | 231 | } | ||
232 | d->form->propertySet()->changeProperty(d->propertyName, d->value); | 232 | d->form->propertySet()->changeProperty(d->propertyName, d->value); | ||
233 | d->form->setUndoing(false); | 233 | d->form->setUndoing(false); | ||
234 | } | 234 | } | ||
235 | 235 | | |||
236 | void PropertyCommand::undo() | 236 | void PropertyCommand::undo() | ||
237 | { | 237 | { | ||
238 | // do not reselect widget; this e.g. avoids removing resize handles | ||||
239 | const bool reSelectWidgets = !d->thisSingleWidgetSelected(); | ||||
240 | if (reSelectWidgets) { | ||||
238 | d->form->selectFormWidget(); | 241 | d->form->selectFormWidget(); | ||
242 | } | ||||
239 | d->form->setUndoing(true); | 243 | d->form->setUndoing(true); | ||
240 | 244 | | |||
241 | QHash<QByteArray, QVariant>::ConstIterator endIt = d->oldValues.constEnd(); | 245 | QHash<QByteArray, QVariant>::ConstIterator endIt = d->oldValues.constEnd(); | ||
242 | for (QHash<QByteArray, QVariant>::ConstIterator it = d->oldValues.constBegin(); it != endIt; ++it) { | 246 | for (QHash<QByteArray, QVariant>::ConstIterator it = d->oldValues.constBegin(); it != endIt; ++it) { | ||
243 | ObjectTreeItem* item = d->form->objectTree()->lookup(it.key()); | 247 | ObjectTreeItem* item = d->form->objectTree()->lookup(it.key()); | ||
244 | if (!item) | 248 | if (!item) | ||
245 | continue; //better this than a crash | 249 | continue; //better this than a crash | ||
246 | QWidget *widget = item->widget(); | 250 | QWidget *widget = item->widget(); | ||
251 | if (reSelectWidgets) { | ||||
247 | d->form->selectWidget(widget, Form::AddToPreviousSelection | Form::LastSelection | Form::Raise); | 252 | d->form->selectWidget(widget, Form::AddToPreviousSelection | Form::LastSelection | Form::Raise); | ||
253 | } | ||||
248 | 254 | | |||
249 | WidgetWithSubpropertiesInterface* subpropIface = dynamic_cast<WidgetWithSubpropertiesInterface*>(widget); | 255 | WidgetWithSubpropertiesInterface* subpropIface = dynamic_cast<WidgetWithSubpropertiesInterface*>(widget); | ||
250 | QWidget *subWidget = (subpropIface && subpropIface->subwidget()) ? subpropIface->subwidget() : widget; | 256 | QWidget *subWidget = (subpropIface && subpropIface->subwidget()) ? subpropIface->subwidget() : widget; | ||
251 | if (subWidget && -1 != subWidget->metaObject()->indexOfProperty(d->propertyName)) { | 257 | if (subWidget && -1 != subWidget->metaObject()->indexOfProperty(d->propertyName)) { | ||
252 | qDebug() << "OLD" << d->propertyName << subWidget->property(d->propertyName); | 258 | //qDebug() << "OLD" << d->propertyName << subWidget->property(d->propertyName); | ||
253 | qDebug() << "NEW" << d->propertyName << it.value(); | 259 | //qDebug() << "NEW" << d->propertyName << it.value(); | ||
254 | subWidget->setProperty(d->propertyName, it.value()); | 260 | subWidget->setProperty(d->propertyName, it.value()); | ||
255 | } | 261 | } | ||
256 | } | 262 | } | ||
257 | 263 | | |||
258 | d->form->propertySet()->changeProperty(d->propertyName, d->oldValues.constBegin().value()); | 264 | d->form->propertySet()->changeProperty(d->propertyName, d->oldValues.constBegin().value()); | ||
259 | d->form->setUndoing(false); | 265 | d->form->setUndoing(false); | ||
260 | } | 266 | } | ||
261 | 267 | | |||
▲ Show 20 Lines • Show All 768 Lines • ▼ Show 20 Line(s) | 965 | //! @todo allow setting this for data view mode as well | |||
1030 | if (!d->form->isRedoing() && !d->form->library()->internalProperty(w->metaObject()->className(), | 1036 | if (!d->form->isRedoing() && !d->form->library()->internalProperty(w->metaObject()->className(), | ||
1031 | "dontStartEditingOnInserting").toBool()) | 1037 | "dontStartEditingOnInserting").toBool()) | ||
1032 | { | 1038 | { | ||
1033 | // edit the widget on creation | 1039 | // edit the widget on creation | ||
1034 | d->form->library()->startInlineEditing( | 1040 | d->form->library()->startInlineEditing( | ||
1035 | w->metaObject()->className(), w, item->container() ? item->container() : container); | 1041 | w->metaObject()->className(), w, item->container() ? item->container() : container); | ||
1036 | } | 1042 | } | ||
1037 | //! @todo update widget's width for entered text's metrics | 1043 | //! @todo update widget's width for entered text's metrics | ||
1038 | //qDebug() << "widget added " << this; | 1044 | //qDebug() << "widget added" << this; | ||
1039 | } | 1045 | } | ||
1040 | 1046 | | |||
1041 | void InsertWidgetCommand::undo() | 1047 | void InsertWidgetCommand::undo() | ||
1042 | { | 1048 | { | ||
1043 | ObjectTreeItem* titem = d->form->objectTree()->lookup(d->widgetName); | 1049 | ObjectTreeItem* titem = d->form->objectTree()->lookup(d->widgetName); | ||
1044 | if (!titem) | 1050 | if (!titem) | ||
1045 | return; //better this than a crash | 1051 | return; //better this than a crash | ||
1046 | QWidget *widget = titem->widget(); | 1052 | QWidget *widget = titem->widget(); | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 1147 | { | |||
1146 | QString errMsg; | 1152 | QString errMsg; | ||
1147 | int errLine; | 1153 | int errLine; | ||
1148 | int errCol; | 1154 | int errCol; | ||
1149 | QDomDocument domDoc("UI"); | 1155 | QDomDocument domDoc("UI"); | ||
1150 | bool parsed = domDoc.setContent(d->data, false, &errMsg, &errLine, &errCol); | 1156 | bool parsed = domDoc.setContent(d->data, false, &errMsg, &errLine, &errCol); | ||
1151 | 1157 | | |||
1152 | if (!parsed) { | 1158 | if (!parsed) { | ||
1153 | qWarning() << errMsg; | 1159 | qWarning() << errMsg; | ||
1154 | qWarning() << "line: " << errLine << "col: " << errCol; | 1160 | qWarning() << "line:" << errLine << "col:" << errCol; | ||
1155 | return; | 1161 | return; | ||
1156 | } | 1162 | } | ||
1157 | 1163 | | |||
1158 | //qDebug() << domDoc.toString(); | 1164 | //qDebug() << domDoc.toString(); | ||
1159 | if (!domDoc.firstChildElement("UI").hasChildNodes()) // nothing in the doc | 1165 | if (!domDoc.firstChildElement("UI").hasChildNodes()) // nothing in the doc | ||
1160 | return; | 1166 | return; | ||
1161 | 1167 | | |||
1162 | QDomElement el = domDoc.firstChildElement("UI").firstChildElement("widget"); | 1168 | QDomElement el = domDoc.firstChildElement("UI").firstChildElement("widget"); | ||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 1305 | { | |||
1310 | QDomElement wi = rect.firstChildElement("width"); | 1316 | QDomElement wi = rect.firstChildElement("width"); | ||
1311 | QDomElement h = rect.firstChildElement("height"); | 1317 | QDomElement h = rect.firstChildElement("height"); | ||
1312 | 1318 | | |||
1313 | int rx = x.text().toInt(); | 1319 | int rx = x.text().toInt(); | ||
1314 | int ry = y.text().toInt(); | 1320 | int ry = y.text().toInt(); | ||
1315 | int rw = wi.text().toInt(); | 1321 | int rw = wi.text().toInt(); | ||
1316 | int rh = h.text().toInt(); | 1322 | int rh = h.text().toInt(); | ||
1317 | QRect r(rx + p.x(), ry + p.y(), rw, rh); | 1323 | QRect r(rx + p.x(), ry + p.y(), rw, rh); | ||
1318 | //qDebug() << "Moving widget by " << p << "from " << rx << ry << "to" << r.topLeft(); | 1324 | //qDebug() << "Moving widget by" << p << "from" << rx << ry << "to" << r.topLeft(); | ||
1319 | 1325 | | |||
1320 | QWidget *w = d->form->widget()->childAt(r.x() + 6, r.y() + 6); | 1326 | QWidget *w = d->form->widget()->childAt(r.x() + 6, r.y() + 6); | ||
1321 | 1327 | | |||
1322 | while (w && (w->geometry() == r)) { // there is already a widget there, with the same size | 1328 | while (w && (w->geometry() == r)) { // there is already a widget there, with the same size | ||
1323 | w = d->form->widget()->childAt(w->x() + 16, w->y() + 16); | 1329 | w = d->form->widget()->childAt(w->x() + 16, w->y() + 16); | ||
1324 | r.translate(10, 10); | 1330 | r.translate(10, 10); | ||
1325 | } | 1331 | } | ||
1326 | 1332 | | |||
▲ Show 20 Lines • Show All 679 Lines • Show Last 20 Lines |