924 m_propertyName == p.m_propertyName && m_propertyGroup == p.m_propertyGroup; |
924 m_propertyName == p.m_propertyName && m_propertyGroup == p.m_propertyGroup; |
925 } |
925 } |
926 |
926 |
927 |
927 |
928 // ---- PropertyListCommand |
928 // ---- PropertyListCommand |
929 PropertyListCommand::PropertyListCommand(QDesignerFormWindowInterface *formWindow) : |
929 PropertyListCommand::PropertyListCommand(QDesignerFormWindowInterface *formWindow, |
930 QDesignerFormWindowCommand(QString(), formWindow) |
930 QUndoCommand *parent) : |
|
931 QDesignerFormWindowCommand(QString(), formWindow, parent) |
931 { |
932 { |
932 } |
933 } |
933 |
934 |
934 const QString PropertyListCommand::propertyName() const |
935 const QString PropertyListCommand::propertyName() const |
935 { |
936 { |
964 // checks: mismatch or only one object in case of name |
965 // checks: mismatch or only one object in case of name |
965 const bool match = m_propertyDescription.equals(description); |
966 const bool match = m_propertyDescription.equals(description); |
966 if (!match || m_propertyDescription.m_specialProperty == SP_ObjectName) |
967 if (!match || m_propertyDescription.m_specialProperty == SP_ObjectName) |
967 return false; |
968 return false; |
968 } |
969 } |
969 m_propertyHelperList.push_back(PropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index)); |
970 |
|
971 const PropertyHelperPtr ph(createPropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index)); |
|
972 m_propertyHelperList.push_back(ph); |
970 return true; |
973 return true; |
971 } |
974 } |
972 |
975 |
|
976 PropertyHelper *PropertyListCommand::createPropertyHelper(QObject *object, SpecialProperty sp, |
|
977 QDesignerPropertySheetExtension *sheet, int sheetIndex) const |
|
978 { |
|
979 return new PropertyHelper(object, sp, sheet, sheetIndex); |
|
980 } |
973 |
981 |
974 // Init from a list and make sure referenceObject is added first to obtain the right property group |
982 // Init from a list and make sure referenceObject is added first to obtain the right property group |
975 bool PropertyListCommand::initList(const ObjectList &list, const QString &apropertyName, QObject *referenceObject) |
983 bool PropertyListCommand::initList(const ObjectList &list, const QString &apropertyName, QObject *referenceObject) |
976 { |
984 { |
977 propertyHelperList().clear(); |
985 propertyHelperList().clear(); |
991 |
999 |
992 |
1000 |
993 QObject* PropertyListCommand::object(int index) const |
1001 QObject* PropertyListCommand::object(int index) const |
994 { |
1002 { |
995 Q_ASSERT(index < m_propertyHelperList.size()); |
1003 Q_ASSERT(index < m_propertyHelperList.size()); |
996 return m_propertyHelperList[index].object(); |
1004 return m_propertyHelperList.at(index)->object(); |
997 } |
1005 } |
998 |
1006 |
999 QVariant PropertyListCommand::oldValue(int index) const |
1007 QVariant PropertyListCommand::oldValue(int index) const |
1000 { |
1008 { |
1001 Q_ASSERT(index < m_propertyHelperList.size()); |
1009 Q_ASSERT(index < m_propertyHelperList.size()); |
1002 return m_propertyHelperList[index].oldValue(); |
1010 return m_propertyHelperList.at(index)->oldValue(); |
1003 } |
1011 } |
1004 |
1012 |
1005 void PropertyListCommand::setOldValue(const QVariant &oldValue, int index) |
1013 void PropertyListCommand::setOldValue(const QVariant &oldValue, int index) |
1006 { |
1014 { |
1007 Q_ASSERT(index < m_propertyHelperList.size()); |
1015 Q_ASSERT(index < m_propertyHelperList.size()); |
1008 m_propertyHelperList[index].setOldValue(oldValue); |
1016 m_propertyHelperList.at(index)->setOldValue(oldValue); |
1009 } |
1017 } |
1010 // ----- SetValueFunction: Set a new value when applied to a PropertyHelper. |
1018 // ----- SetValueFunction: Set a new value when applied to a PropertyHelper. |
1011 class SetValueFunction { |
1019 class SetValueFunction { |
1012 public: |
1020 public: |
1013 SetValueFunction(QDesignerFormWindowInterface *formWindow, const PropertyHelper::Value &newValue, unsigned subPropertyMask); |
1021 SetValueFunction(QDesignerFormWindowInterface *formWindow, const PropertyHelper::Value &newValue, unsigned subPropertyMask); |
1063 unsigned updateMask = 0; |
1071 unsigned updateMask = 0; |
1064 QDesignerPropertyEditorInterface *propertyEditor = core->propertyEditor(); |
1072 QDesignerPropertyEditorInterface *propertyEditor = core->propertyEditor(); |
1065 bool updatedPropertyEditor = false; |
1073 bool updatedPropertyEditor = false; |
1066 |
1074 |
1067 for (PropertyListIterator it = begin; it != end; ++it) { |
1075 for (PropertyListIterator it = begin; it != end; ++it) { |
1068 if (QObject* object = it->object()) { // Might have been deleted in the meantime |
1076 PropertyHelper *ph = it->data(); |
1069 const PropertyHelper::Value newValue = function(*it); |
1077 if (QObject* object = ph->object()) { // Might have been deleted in the meantime |
1070 updateMask |= it->updateMask(); |
1078 const PropertyHelper::Value newValue = function( *ph ); |
|
1079 updateMask |= ph->updateMask(); |
1071 // Update property editor if it is the current object |
1080 // Update property editor if it is the current object |
1072 if (!updatedPropertyEditor && propertyEditor && object == propertyEditor->object()) { |
1081 if (!updatedPropertyEditor && propertyEditor && object == propertyEditor->object()) { |
1073 propertyEditor->setPropertyValue(propertyName, newValue.first, newValue.second); |
1082 propertyEditor->setPropertyValue(propertyName, newValue.first, newValue.second); |
1074 updatedPropertyEditor = true; |
1083 updatedPropertyEditor = true; |
1075 } |
1084 } |
1082 |
1091 |
1083 // set a new value, return update mask |
1092 // set a new value, return update mask |
1084 unsigned PropertyListCommand::setValue(QVariant value, bool changed, unsigned subPropertyMask) |
1093 unsigned PropertyListCommand::setValue(QVariant value, bool changed, unsigned subPropertyMask) |
1085 { |
1094 { |
1086 if(debugPropertyCommands) |
1095 if(debugPropertyCommands) |
1087 qDebug() << "PropertyListCommand::setValue(" << value << changed << subPropertyMask << ')'; |
1096 qDebug() << "PropertyListCommand::setValue(" << value |
|
1097 << changed << subPropertyMask << ')'; |
1088 return changePropertyList(formWindow()->core(), |
1098 return changePropertyList(formWindow()->core(), |
1089 m_propertyDescription.m_propertyName, m_propertyHelperList.begin(), m_propertyHelperList.end(), |
1099 m_propertyDescription.m_propertyName, |
|
1100 m_propertyHelperList.begin(), m_propertyHelperList.end(), |
1090 SetValueFunction(formWindow(), PropertyHelper::Value(value, changed), subPropertyMask)); |
1101 SetValueFunction(formWindow(), PropertyHelper::Value(value, changed), subPropertyMask)); |
1091 } |
1102 } |
1092 |
1103 |
1093 // restore old value, return update mask |
1104 // restore old value, return update mask |
1094 unsigned PropertyListCommand::restoreOldValue() |
1105 unsigned PropertyListCommand::restoreOldValue() |
1144 bool PropertyListCommand::canMergeLists(const PropertyHelperList& other) const |
1155 bool PropertyListCommand::canMergeLists(const PropertyHelperList& other) const |
1145 { |
1156 { |
1146 if (m_propertyHelperList.size() != other.size()) |
1157 if (m_propertyHelperList.size() != other.size()) |
1147 return false; |
1158 return false; |
1148 for (int i = 0; i < m_propertyHelperList.size(); i++) { |
1159 for (int i = 0; i < m_propertyHelperList.size(); i++) { |
1149 if (!m_propertyHelperList[i].canMerge(other[i])) |
1160 if (!m_propertyHelperList.at(i)->canMerge(*other.at(i))) |
1150 return false; |
1161 return false; |
1151 } |
1162 } |
1152 return true; |
1163 return true; |
1153 } |
1164 } |
1154 |
1165 |
1155 // ---- SetPropertyCommand ---- |
1166 // ---- SetPropertyCommand ---- |
1156 SetPropertyCommand::SetPropertyCommand(QDesignerFormWindowInterface *formWindow) |
1167 SetPropertyCommand::SetPropertyCommand(QDesignerFormWindowInterface *formWindow, |
1157 : PropertyListCommand(formWindow), |
1168 QUndoCommand *parent) |
|
1169 : PropertyListCommand(formWindow, parent), |
1158 m_subPropertyMask(SubPropertyAll) |
1170 m_subPropertyMask(SubPropertyAll) |
1159 { |
1171 { |
1160 } |
1172 } |
1161 |
1173 |
1162 bool SetPropertyCommand::init(QObject *object, const QString &apropertyName, const QVariant &newValue) |
1174 bool SetPropertyCommand::init(QObject *object, const QString &apropertyName, const QVariant &newValue) |
1208 } |
1220 } |
1209 |
1221 |
1210 void SetPropertyCommand::setDescription() |
1222 void SetPropertyCommand::setDescription() |
1211 { |
1223 { |
1212 if (propertyHelperList().size() == 1) { |
1224 if (propertyHelperList().size() == 1) { |
1213 setText(QApplication::translate("Command", "Changed '%1' of '%2'").arg(propertyName()).arg(propertyHelperList()[0].object()->objectName())); |
1225 setText(QApplication::translate("Command", "Changed '%1' of '%2'").arg(propertyName()).arg(propertyHelperList().at(0)->object()->objectName())); |
1214 } else { |
1226 } else { |
1215 int count = propertyHelperList().size(); |
1227 int count = propertyHelperList().size(); |
1216 setText(QApplication::translate("Command", "Changed '%1' of %n objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName())); |
1228 setText(QApplication::translate("Command", "Changed '%1' of %n objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName())); |
1217 } |
1229 } |
1218 } |
1230 } |
1246 if (!propertyDescription().equals(cmd->propertyDescription()) || |
1263 if (!propertyDescription().equals(cmd->propertyDescription()) || |
1247 m_subPropertyMask != cmd->m_subPropertyMask || |
1264 m_subPropertyMask != cmd->m_subPropertyMask || |
1248 !canMergeLists(cmd->propertyHelperList())) |
1265 !canMergeLists(cmd->propertyHelperList())) |
1249 return false; |
1266 return false; |
1250 |
1267 |
1251 m_newValue = cmd->newValue(); |
1268 const QVariant newValue = mergeValue(cmd->newValue()); |
|
1269 if (!newValue.isValid()) |
|
1270 return false; |
|
1271 m_newValue = newValue; |
1252 m_subPropertyMask |= cmd->m_subPropertyMask; |
1272 m_subPropertyMask |= cmd->m_subPropertyMask; |
1253 if(debugPropertyCommands) |
1273 if(debugPropertyCommands) |
1254 qDebug() << "SetPropertyCommand::mergeWith() succeeded " << propertyName(); |
1274 qDebug() << "SetPropertyCommand::mergeWith() succeeded " << propertyName(); |
1255 |
1275 |
1256 return true; |
1276 return true; |
1287 } |
1307 } |
1288 |
1308 |
1289 void ResetPropertyCommand::setDescription() |
1309 void ResetPropertyCommand::setDescription() |
1290 { |
1310 { |
1291 if (propertyHelperList().size() == 1) { |
1311 if (propertyHelperList().size() == 1) { |
1292 setText(QApplication::translate("Command", "Reset '%1' of '%2'").arg(propertyName()).arg(propertyHelperList()[0].object()->objectName())); |
1312 setText(QApplication::translate("Command", "Reset '%1' of '%2'").arg(propertyName()).arg(propertyHelperList().at(0)->object()->objectName())); |
1293 } else { |
1313 } else { |
1294 int count = propertyHelperList().size(); |
1314 int count = propertyHelperList().size(); |
1295 setText(QApplication::translate("Command", "Reset '%1' of %n objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName())); |
1315 setText(QApplication::translate("Command", "Reset '%1' of %n objects", "", QCoreApplication::UnicodeUTF8, count).arg(propertyName())); |
1296 } |
1316 } |
1297 } |
1317 } |