OSDN Git Service

QmlDesigner.StatesEditor: Optimize updating
authorMarco Bubke <marco.bubke@nokia.com>
Wed, 12 Jan 2011 18:06:57 +0000 (19:06 +0100)
committerMarco Bubke <marco.bubke@nokia.com>
Wed, 12 Jan 2011 18:06:57 +0000 (19:06 +0100)
src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp
src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h
src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp

index a85837b..43bc291 100644 (file)
@@ -148,12 +148,10 @@ void StatesEditorModel::insertState(int stateIndex)
     }
 }
 
-void StatesEditorModel::updateState(int updateIndex)
+void StatesEditorModel::updateState(int beginIndex, int endIndex)
 {
-    if (updateIndex >= 0) {
-        QModelIndex modelIndex = index(updateIndex, 0);
-        emit dataChanged(modelIndex, modelIndex);
-    }
+    if (beginIndex >= 0 && endIndex >= 0)
+        emit dataChanged(index(beginIndex, 0), index(endIndex, 0));
 }
 
 void StatesEditorModel::removeState(int stateIndex)
index 0e1e9e3..5d8c5ab 100644 (file)
@@ -64,7 +64,7 @@ public:
 
     void insertState(int stateIndex);
     void removeState(int stateIndex);
-    void updateState(int stateIndex);
+    void updateState(int beginIndex, int endIndex);
     Q_INVOKABLE void renameState(int nodeId, const QString &newName);
     void emitChangedToState(int n);
 
index b53c60b..ffcd30b 100644 (file)
@@ -247,14 +247,6 @@ void StatesEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>
 
 void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &propertyList, PropertyChangeFlags /*propertyChange*/)
 {
-    foreach (const VariantProperty &property, propertyList) {
-        if (property.name() == "name" && property.parentModelNode().hasParentProperty()) {
-            NodeAbstractProperty parentProperty = property.parentModelNode().parentProperty();
-            if (parentProperty.name() == "states" && parentProperty.parentModelNode().isRootNode()) {
-                m_statesEditorModel->updateState(parentProperty.indexOf(property.parentModelNode()) + 1);
-            }
-        }
-    }
 }
 
 
@@ -338,15 +330,24 @@ void StatesEditorView::customNotification(const AbstractView * view, const QStri
 {
 
     if (identifier == "__instance preview image changed__")   {
+        int minimumIndex = 10000;
+        int maximumIndex = -1;
         foreach(const ModelNode &node, nodeList) {
             if (node.isRootNode()) {
-                m_statesEditorModel->updateState(0);
+                minimumIndex = qMin(minimumIndex, 0);
+                maximumIndex = qMax(maximumIndex, 0);
             } else {
                 int index = rootStateGroup().allStates().indexOf(QmlModelState(node)) + 1;
-                if (index > 0)
-                    m_statesEditorModel->updateState(index);
+                if (index > 0) {
+                    minimumIndex = qMin(minimumIndex, index);
+                    maximumIndex = qMax(maximumIndex, index);
+                }
             }
         }
+
+        if (maximumIndex >= 0)
+            m_statesEditorModel->updateState(minimumIndex, maximumIndex);
+
     } else {
         QmlModelView::customNotification(view, identifier, nodeList, imageList);
     }