[Kst] branches/work/kst/portto4/kst/src/libkstapp
Nicolas Brisset
nicolas.brisset at eurocopter.com
Fri Oct 1 00:16:48 CEST 2010
SVN commit 1181400 by brisset:
Start fixing the change data file bug. Not 100% complete yet. It works
for curves at least, but has to be checked for data objects. Matrices
not handled yet. Also fix some small issues along the way, and change
one UI string...
I'd appreciate if someone could check the changes because it is
definitely more complex than what I've done up to now. The areas I'm
particularly worried about are:
- the locks I added (because relation.h I think mentioned that when
calling inputVectors() it was required): are they OK?
- the casts (kst_cast<T>()), which cost me most of the time it took to
make the changes!
CCBUG: 252874
M +34 -42 changefiledialog.cpp
M +1 -2 changefiledialog.h
M +1 -1 changefiledialog.ui
--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.cpp #1181399:1181400
@@ -317,7 +317,7 @@
if (invalid > 0) {
invalidSources += ", ";
}
- invalidSources = vector->field();
+ invalidSources += vector->field();
++invalid;
} else {
if (_duplicateSelected->isChecked()) {
@@ -327,10 +327,7 @@
newVector->changeFile(_dataSource);
newVector->registerChange();
newVector->unlock();
-
- if (_duplicateDependents->isChecked()) {
- duplicateDependents(VectorPtr(vector), VectorPtr(newVector), duplicatedRelations);
- }
+ duplicatedVectors[vector] = newVector;
} else {
if (!oldSources.contains(vector->dataSource())) {
oldSources << vector->dataSource();
@@ -351,7 +348,7 @@
if (invalid > 0) {
invalidSources += ", ";
}
- invalidSources = matrix->field();
+ invalidSources += matrix->field();
++invalid;
} else {
if (_duplicateSelected->isChecked()) {
@@ -361,10 +358,7 @@
newMatrix->changeFile(_dataSource);
newMatrix->registerChange();
newMatrix->unlock();
-
- if (_duplicateDependents->isChecked()) {
- duplicateDependents(MatrixPtr(matrix), MatrixPtr(newMatrix), duplicatedRelations);
- }
+ duplicatedMatrices[matrix] = newMatrix;
} else {
if (!oldSources.contains(matrix->dataSource())) {
oldSources << matrix->dataSource();
@@ -379,6 +373,9 @@
}
}
+ // Now that all new primitives have been created, generate derived objects
+ duplicateDerivedObjects(duplicatedVectors, duplicatedMatrices, duplicatedRelations);
+
// Plot the items. (Do we need to doUpdates before this?)
foreach (PlotItemInterface *plot, Data::self()->plotList()) {
PlotItem* plotItem = static_cast<PlotItem*>(plot);
@@ -413,52 +410,47 @@
}
-void ChangeFileDialog::duplicateDependents(VectorPtr oldVector, VectorPtr newVector, QMap<RelationPtr, RelationPtr> &duplicatedRelations) {
+void ChangeFileDialog::duplicateDerivedObjects(QMap<DataVectorPtr, DataVectorPtr> duplicatedVectors, QMap<DataMatrixPtr, DataMatrixPtr> duplicatedMatrices, QMap<RelationPtr, RelationPtr> &duplicatedRelations) {
+ // First, take care of curves ("relations")
RelationList relations = _store->getObjects<Relation>();
foreach(RelationPtr relation, relations) {
- if (relation->uses(oldVector)){
- RelationPtr newRelation = relation->makeDuplicate(duplicatedRelations);
- if (newRelation) {
- newRelation->replaceDependency(oldVector, newVector);
+ relation->readLock();
+ bool relationDuplicated = false;
+ RelationPtr newRelation = NULL;
+ foreach(VectorPtr inputVector, relation->inputVectors().values()) {
+ if (duplicatedVectors.value(kst_cast<DataVector>(inputVector))) {
+ if (!relationDuplicated) { // For the first duplicated vector, create the new relation
+ newRelation = relation->makeDuplicate(duplicatedRelations);
+ relationDuplicated = true;
}
+ if (newRelation) { // For the others, substitute the duplicated vector to be used in the duplicated relation
+ newRelation->replaceDependency(inputVector, duplicatedVectors[kst_cast<DataVector>(inputVector)]);
}
}
-
+ }
+ relation->unlock();
+ }
+ // Now data objects (equations, etc...)
DataObjectList dataObjects = _store->getObjects<DataObject>();
foreach(DataObjectPtr dataObject, dataObjects) {
- if (dataObject->uses(oldVector)){
- DataObjectPtr newObject = dataObject->makeDuplicate();
- if (newObject) {
- newObject->replaceDependency(oldVector, newVector);
- dataObject->duplicateDependents(newObject, duplicatedRelations);
+ dataObject->readLock();
+ bool dataObjectDuplicated = false;
+ DataObjectPtr newDataObject = NULL;
+ foreach(VectorPtr inputVector, dataObject->inputVectors().values()) {
+ if (duplicatedVectors.value(kst_cast<DataVector>(inputVector))) {
+ if (!dataObjectDuplicated) {
+ newDataObject = dataObject->makeDuplicate();
+ dataObjectDuplicated = true;
}
+ if (newDataObject) { // For the others, substitute the duplicated vector to be used in the duplicated relation
+ newDataObject->replaceDependency(inputVector, duplicatedVectors[kst_cast<DataVector>(inputVector)]);
}
}
}
-
-
-void ChangeFileDialog::duplicateDependents(MatrixPtr oldMatrix, MatrixPtr newMatrix, QMap<RelationPtr, RelationPtr> &duplicatedRelations) {
- RelationList relations = _store->getObjects<Relation>();
- foreach(RelationPtr relation, relations) {
- if (relation->uses(oldMatrix)){
- RelationPtr newRelation = relation->makeDuplicate(duplicatedRelations);
- if (newRelation) {
- newRelation->replaceDependency(oldMatrix, newMatrix);
+ dataObject->unlock();
}
}
- }
- DataObjectList dataObjects = _store->getObjects<DataObject>();
- foreach(DataObjectPtr dataObject, dataObjects) {
- if (dataObject->uses(oldMatrix)){
- DataObjectPtr newObject = dataObject->makeDuplicate();
- if (newObject) {
- newObject->replaceDependency(oldMatrix, newMatrix);
- dataObject->duplicateDependents(newObject, duplicatedRelations);
- }
- }
- }
-}
}
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.h #1181399:1181400
@@ -54,8 +54,7 @@
private:
void updatePrimitiveList();
- void duplicateDependents(VectorPtr oldVector, VectorPtr newVector, QMap<RelationPtr, RelationPtr> &duplicatedRelations);
- void duplicateDependents(MatrixPtr oldMatrix, MatrixPtr newMatrix, QMap<RelationPtr, RelationPtr> &duplicatedRelations);
+ void duplicateDerivedObjects(QMap<DataVectorPtr, DataVectorPtr> duplicatedVectors, QMap<DataMatrixPtr, DataMatrixPtr> duplicatedMatrices, QMap<RelationPtr, RelationPtr> &duplicatedRelations);
ObjectStore *_store;
DataSourcePtr _dataSource;
--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.ui #1181399:1181400
@@ -263,7 +263,7 @@
<bool>false</bool>
</property>
<property name="text">
- <string>D&uplicate dependents</string>
+ <string>D&uplicate derived objects (curves, equations, ...)</string>
</property>
<property name="checked">
<bool>true</bool>
More information about the Kst
mailing list