Git commit e800833ac1fe0cd4fa50cec480f8117ce36cd83b by Andreas Cord-Landweh= r. Committed on 22/09/2012 at 21:49. Pushed by cordlandwehr into branch 'dataUseOnlyDynamicProperties'. Fix unit tests. M +0 -31 src/Core/DataStructure.cpp M +0 -2 src/Core/DataStructure.h M +1 -1 src/Interface/DataPropertiesWidget.cpp M +1 -1 src/Interface/PointerPropertiesWidget.cpp M +9 -18 src/Models/model_GraphProperties.cpp M +1 -1 src/Models/model_GraphProperties.h M +12 -113 src/Tests/TestDynamicProperties.cpp M +0 -8 src/Tests/TestDynamicProperties.h http://commits.kde.org/rocs/e800833ac1fe0cd4fa50cec480f8117ce36cd83b diff --git a/src/Core/DataStructure.cpp b/src/Core/DataStructure.cpp index fd4e3d5..e151c96 100644 --- a/src/Core/DataStructure.cpp +++ b/src/Core/DataStructure.cpp @@ -367,9 +367,6 @@ DataPtr DataStructure::addData(QString name, int dataTy= pe) = DataPtr n =3D Data::create(this->getDataStructure(), generateUniqueIde= ntifier(), dataType); = - if (n->property("name") =3D=3D QVariant::Invalid) { - document()->dataType(dataType)->addProperty("name"); - } n->setProperty("name", name); return addData(n, dataType); } @@ -572,20 +569,6 @@ void DataStructure::removeDynamicProperty(const QStrin= g& property) } = = -void DataStructure::addDataDynamicProperty(const QString& property, QVaria= nt value) -{ - // do not change properties concurrently, not thread safe - foreach(const DataList& dataType, d->_dataTypeLists) { - DataList::const_iterator data =3D dataType.constBegin(); - while (data !=3D dataType.constEnd()) { - (*data)->addDynamicProperty(property, value); - ++data; - } - } - d->m_globalPropertiesData.insert(property, value); -} - - void DataStructure::addPointersDynamicProperty(const QString& property, QV= ariant value) { // do not change properties concurrently, not thread safe @@ -599,20 +582,6 @@ void DataStructure::addPointersDynamicProperty(const Q= String& property, QVariant d->m_globalPropertiesData.insert(property, value); } = - -void DataStructure::removeDataDynamicProperty(const QString& property) -{ - // do not change properties concurrently, not thread safe - foreach(const DataList& dataType, d->_dataTypeLists) { - DataList::const_iterator data =3D dataType.constBegin(); - while (data !=3D dataType.constEnd()) { - (*data)->removeDynamicProperty(property); - ++data; - } - } - d->m_globalPropertiesData.remove(property); -} - void DataStructure::removePointersDynamicProperty(const QString& property) { // do not change properties concurrently, not thread safe diff --git a/src/Core/DataStructure.h b/src/Core/DataStructure.h index aa4cafc..8724220 100644 --- a/src/Core/DataStructure.h +++ b/src/Core/DataStructure.h @@ -204,10 +204,8 @@ public slots: /** * add dynamic property to all data elements of data structure */ - void addDataDynamicProperty(const QString& property, QVariant value = =3D QVariant(0)); void addPointersDynamicProperty(const QString& property, QVariant valu= e =3D QVariant(0)); = - void removeDataDynamicProperty(const QString& property); void removePointersDynamicProperty(const QString& property); = /** diff --git a/src/Interface/DataPropertiesWidget.cpp b/src/Interface/DataPro= pertiesWidget.cpp index 03811c1..38e71a8 100644 --- a/src/Interface/DataPropertiesWidget.cpp +++ b/src/Interface/DataPropertiesWidget.cpp @@ -163,5 +163,5 @@ void DataPropertiesWidget::updateDataTypes() void DataPropertiesWidget::addProperty() { GraphPropertiesModel *model =3D qobject_cast< GraphPropertiesModel*>(u= i->_propertiesTable->model()); - model->addDynamicProperty(i18n("untitled %1", model->rowCount()), 0, _= data.get(), false); + model->addDynamicProperty(i18n("untitled%1", model->rowCount()), 0, _d= ata.get()); } diff --git a/src/Interface/PointerPropertiesWidget.cpp b/src/Interface/Poin= terPropertiesWidget.cpp index 6c39b59..0cd6f73 100644 --- a/src/Interface/PointerPropertiesWidget.cpp +++ b/src/Interface/PointerPropertiesWidget.cpp @@ -104,7 +104,7 @@ void PointerPropertiesWidget::on__addProperty_clicked() = GraphPropertiesModel *model =3D qobject_cast< GraphPropertiesModel*>(= ui->_propertiesTable->model()); model->addDynamicProperty(ui->_propertyName->text(), QVariant(ui->_pro= pertyValue->text()), - _pointer.get(), (ui->_isPropertyGlobal->chec= kState() =3D=3D Qt::Checked)); + _pointer.get()); } = = diff --git a/src/Models/model_GraphProperties.cpp b/src/Models/model_GraphP= roperties.cpp index c05199e..248ab8f 100644 --- a/src/Models/model_GraphProperties.cpp +++ b/src/Models/model_GraphProperties.cpp @@ -154,7 +154,7 @@ bool GraphPropertiesModel::setData(const QModelIndex &i= ndex, const QVariant &val = } = -void GraphPropertiesModel::addDynamicProperty(QString name, QVariant value= , QObject *obj, bool isGlobal) +void GraphPropertiesModel::addDynamicProperty(QString name, QVariant value= , QObject *obj) { // Need check if the propertie already exists bool insertingRow =3D false; @@ -168,23 +168,14 @@ void GraphPropertiesModel::addDynamicProperty(QString= name, QVariant value, QObj insertingRow =3D true; } = - if (isGlobal) { - if (Pointer * pointer =3D qobject_cast (obj)) { - pointer->dataStructure()->addPointersDynamicProperty(name, val= ue); - } - if (Data * datum =3D qobject_cast (obj)) { - datum->dataStructure()->addDataDynamicProperty(name, value); - } - } else { - if (Pointer * pointer =3D qobject_cast (obj)) { - pointer->addDynamicProperty(name, value); - } - if (Data * datum =3D qobject_cast (obj)) { - datum->addDynamicProperty(name, value); - } - if (DataStructure * dataStructure =3D qobject_cast= (obj)) { - dataStructure->addDynamicProperty(name, value); - } + if (Pointer * pointer =3D qobject_cast (obj)) { + pointer->addDynamicProperty(name, value); + } + if (Data * datum =3D qobject_cast (obj)) { + datum->addDynamicProperty(name, value); + } + if (DataStructure * dataStructure =3D qobject_cast (ob= j)) { + dataStructure->addDynamicProperty(name, value); } = if (insertingRow) { /* if inserting, need finish*/ diff --git a/src/Models/model_GraphProperties.h b/src/Models/model_GraphPro= perties.h index 08d9373..e42d535 100644 --- a/src/Models/model_GraphProperties.h +++ b/src/Models/model_GraphProperties.h @@ -66,7 +66,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; = /**Add properti to data source and insert a new row,*/ - void addDynamicProperty(QString name, QVariant value, QObject *obj, bo= ol isGlobal); + void addDynamicProperty(QString name, QVariant value, QObject *obj); = private: QObject *_dataSource; diff --git a/src/Tests/TestDynamicProperties.cpp b/src/Tests/TestDynamicPro= perties.cpp index 72d4d28..65df209 100644 --- a/src/Tests/TestDynamicProperties.cpp +++ b/src/Tests/TestDynamicProperties.cpp @@ -79,52 +79,23 @@ void TestDynamicProperties::addGraphDynamicProperty() QVERIFY2(DynamicPropertiesList::New()->type(g.get(), property) =3D=3D = Unique, "Property isn't Unique."); } = -void TestDynamicProperties::addToAllNodes() -{ - DataStructurePtr g =3D _document->addDataStructure("A graph"); - - DataPtr n =3D g->addData("Node1"); - DataPtr n2 =3D g->addData("Node2"); - - QByteArray property =3D "newProperty"; - g->addDataDynamicProperty(property); - QVERIFY2(n->property(property) !=3D QVariant::Invalid, "Property not a= dded to Node1."); - QVERIFY2(n2->property(property) !=3D QVariant::Invalid, "Property not = added to Node2."); - QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) =3D=3D = Global, "Property isn't Global. (by node 1)"); - QVERIFY2(DynamicPropertiesList::New()->type(n2.get(), property) =3D=3D= Global, "Property isn't Global. (by node 2)"); -} - -void TestDynamicProperties::addToAllEdges() -{ - DataStructurePtr g =3D _document->addDataStructure("A graph"); - - DataPtr n1 =3D g->addData("Node"); - DataPtr n2 =3D g->addData("Node"); - DataPtr n3 =3D g->addData("Node"); - PointerPtr e =3D g->addPointer(n1, n2); - PointerPtr e2 =3D g->addPointer(n2, n3); - PointerPtr e3 =3D g->addPointer(n1, n3); - - QByteArray property =3D "newProperty"; - g->addPointersDynamicProperty(property, QVariant(0)); - QVERIFY2(e->property(property) !=3D QVariant::Invalid, "Property not a= dded."); - QVERIFY2(DynamicPropertiesList::New()->type(e.get(), property) =3D=3D = Global, "Property isn't Global. (by Edge 1)"); - QVERIFY2(DynamicPropertiesList::New()->type(e2.get(), property) =3D=3D= Global, "Property isn't Global. (by Edge 2)"); - QVERIFY2(DynamicPropertiesList::New()->type(e3.get(), property) =3D=3D= Global, "Property isn't Global. (by Edge 3)"); -} - void TestDynamicProperties::removeNodeDynamicProperty() { DataStructurePtr g =3D _document->addDataStructure("A graph"); = DataPtr n =3D g->addData("Node"); QByteArray property =3D "newProperty"; + int propertyNumber =3D n->dynamicPropertyNames().size(); + n->addDynamicProperty(property, QVariant(0)); QVERIFY2(n->property(property) !=3D QVariant::Invalid, "Property not a= dded."); + QVERIFY(n->dynamicPropertyNames().size() =3D=3D propertyNumber+1); + n->removeDynamicProperty(property); QVERIFY2(n->property(property) =3D=3D QVariant::Invalid, "Property not= removed."); QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) =3D=3D = None, "Property isn't None."); - QVERIFY2(n->dynamicPropertyNames().size() =3D=3D 0, "Still having prop= erty."); + + QVERIFY2(n->dynamicPropertyNames().size() =3D=3D propertyNumber, "Stil= l having property."); } = void TestDynamicProperties::removeEdgeDynamicProperty() @@ -156,79 +127,6 @@ void TestDynamicProperties::removeGraphDynamicProperty= () QVERIFY2(g->dynamicPropertyNames().size() =3D=3D 0, "Still having prop= erty."); } = -void TestDynamicProperties::removeToAllNodes() -{ - DataStructurePtr g =3D _document->addDataStructure("A graph"); - - DataPtr n =3D g->addData("Node 1"); - DataPtr n2 =3D g->addData("Node 2"); - - QByteArray property =3D "newProperty"; - g->addDataDynamicProperty(property, QVariant(0)); - - QVERIFY2(n->property(property) !=3D QVariant::Invalid, "Property not a= dded."); - QVERIFY2(n2->property(property) !=3D QVariant::Invalid, "Property not = added."); - - g->removeDataDynamicProperty(property); - QVERIFY2(n->property(property) =3D=3D QVariant::Invalid, "Property not= removed from node 1."); - QVERIFY2(n2->property(property) =3D=3D QVariant::Invalid, "Property no= t removedfrom node 2."); - QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) =3D=3D = None, "Property isn't None."); -} - -void TestDynamicProperties::removeToAllEdges() -{ - DataStructurePtr g =3D _document->addDataStructure("A graph"); - - DataPtr n1 =3D g->addData("1"); - DataPtr n2 =3D g->addData("2"); - DataPtr n3 =3D g->addData("3"); - PointerPtr e =3D g->addPointer(n1, n2); - PointerPtr e2 =3D g->addPointer(n2, n3); - QByteArray property =3D "newProperty"; - g->addPointersDynamicProperty(property, QVariant(0)); - - QVERIFY2(e->property(property) !=3D QVariant::Invalid, "Property not a= dded to edge 2."); - QVERIFY2(e2->property(property) !=3D QVariant::Invalid, "Property not = added to edge 2."); - g->removePointersDynamicProperty(property); - QVERIFY2(e->property(property) =3D=3D QVariant::Invalid, "Property not= removed from edge 1."); - QVERIFY2(e2->property(property) =3D=3D QVariant::Invalid, "Property no= t removed from edge 2."); - QVERIFY2(DynamicPropertiesList::New()->type(e.get(), property) =3D=3D = None, "Property isn't None."); -} - -void TestDynamicProperties::MultipleProperties() -{ - DataStructurePtr g =3D _document->addDataStructure("A graph"); - - DataPtr n1 =3D g->addData("Node 1"); - DataPtr n2 =3D g->addData("Node 2"); - DataPtr n3 =3D g->addData("Node 3"); - PointerPtr e1 =3D g->addPointer(n3, n1); - PointerPtr e2 =3D g->addPointer(n2, n1); - PointerPtr e3 =3D g->addPointer(n3, n2); - - QByteArray property =3D "newProperty"; - g->addDataDynamicProperty(property, QVariant(0)); - g->addPointersDynamicProperty(property, QVariant(0)); - - QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) =3D=3D= Global, "Property isn't global"); - QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) =3D=3D= Global, "Property isn't global"); - - n1->removeDynamicProperty(property); - e1->removeDynamicProperty(property); - QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) =3D=3D= Multiple, "Property isn't Multiple"); - QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) =3D=3D= Multiple, "Property isn't Multiple"); - - n2->removeDynamicProperty(property); - e2->removeDynamicProperty(property); - QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) =3D=3D= Unique, "Property isn't Unique"); - QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) =3D=3D= Unique, "Property isn't Unique"); - - n3->removeDynamicProperty(property); - e3->removeDynamicProperty(property); - QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) =3D=3D= None, "Property isn't None"); - QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) =3D=3D= None, "Property isn't Unique"); -} - void TestDynamicProperties::changeNames() { DataStructurePtr g =3D _document->addDataStructure("A graph"); @@ -238,7 +136,8 @@ void TestDynamicProperties::changeNames() PointerPtr e =3D g->addPointer(n1, n2); = QString property =3D "newProperty"; - g->addDataDynamicProperty(property, QVariant(0)); + n1->addDynamicProperty(property, QVariant(0)); + n2->addDynamicProperty(property, QVariant(0)); g->addPointersDynamicProperty(property, QVariant(0)); g->addDynamicProperty(property, QVariant(0)); = @@ -246,10 +145,10 @@ void TestDynamicProperties::changeNames() DynamicPropertiesList::New()->changePropertyName(property, QString("ne= wName_Edge"), e.get()); DynamicPropertiesList::New()->changePropertyName(property, QString("ne= wName_Graph"), g.get()); = - QCOMPARE(n1->dynamicPropertyNames() [0], QByteArray("newName_Node")); - QCOMPARE(n2->dynamicPropertyNames() [0], QByteArray("newName_Node")); - QCOMPARE(e->dynamicPropertyNames() [0], QByteArray("newName_Edge")); - QCOMPARE(g->dynamicPropertyNames() [0], QByteArray("newName_Graph")); + QVERIFY(n1->dynamicPropertyNames().contains(QByteArray("newName_Node")= )); + QVERIFY(n2->dynamicPropertyNames().contains(QByteArray("newName_Node")= )); + QCOMPARE(e->dynamicPropertyNames()[0], QByteArray("newName_Edge")); + QCOMPARE(g->dynamicPropertyNames()[0], QByteArray("newName_Graph")); } = QTEST_MAIN(TestDynamicProperties) diff --git a/src/Tests/TestDynamicProperties.h b/src/Tests/TestDynamicPrope= rties.h index 022a66e..6ecce89 100644 --- a/src/Tests/TestDynamicProperties.h +++ b/src/Tests/TestDynamicProperties.h @@ -37,18 +37,10 @@ private slots: void addEdgeDynamicProperty(); void addGraphDynamicProperty(); = - void addToAllNodes(); - void addToAllEdges(); - void removeNodeDynamicProperty(); void removeEdgeDynamicProperty(); void removeGraphDynamicProperty(); = - void removeToAllNodes(); - void removeToAllEdges(); - - void MultipleProperties(); - void changeNames(); = private: