diff --git a/GUI/coregui/Models/FitModelHelper.cpp b/GUI/coregui/Models/FitModelHelper.cpp index 90839bd79aec4d3de4b18ef9af4dab3304a7b37d..2999d5fcd8103d7d0449ca7d5d03a0164ffc98b5 100644 --- a/GUI/coregui/Models/FitModelHelper.cpp +++ b/GUI/coregui/Models/FitModelHelper.cpp @@ -34,8 +34,8 @@ void FitModelHelper::createFitParameter(FitParameterContainerItem *container, Pa SessionItem *link = fitPar->model()->insertNewItem(Constants::FitParameterLinkType, fitPar->index()); Q_ASSERT(link); link->setItemValue(FitParameterLinkItem::P_LINK, "xxx"); - SessionItem *link2 = fitPar->model()->insertNewItem(Constants::FitParameterLinkType, fitPar->index()); - link2->setItemValue(FitParameterLinkItem::P_LINK, "yyy"); +// SessionItem *link2 = fitPar->model()->insertNewItem(Constants::FitParameterLinkType, fitPar->index()); +// link2->setItemValue(FitParameterLinkItem::P_LINK, "yyy"); if(parameterItem) { diff --git a/GUI/coregui/Models/FitParameterAbsModel.cpp b/GUI/coregui/Models/FitParameterAbsModel.cpp index 9be548ca7179b466a396e145e0631eef4bb84d38..ce0e45e236b17552c3acf7892cfcda010f634f3f 100644 --- a/GUI/coregui/Models/FitParameterAbsModel.cpp +++ b/GUI/coregui/Models/FitParameterAbsModel.cpp @@ -95,8 +95,8 @@ QModelIndex FitParameterAbsModel::parent(const QModelIndex &child) const if (SessionItem *parent_item = child_item->parent()) { if(parent_item->modelType()==Constants::FitParameterLinkType) { // qDebug() << "FitParameterAbsModel::parent" << child_item->modelType() << parent_item->modelType(); - - return createIndex(0, 0, parent_item->parent()); + SessionItem *fitPar = parent_item->parent(); + return createIndex(fitPar->parentRow(), 0, fitPar); } } diff --git a/Tests/UnitTests/GUI/TestFitParameterModel.h b/Tests/UnitTests/GUI/TestFitParameterModel.h index f294836690e0eed4751735c4a10124a18e391d1c..301e3cbff3954120b0621d343a6040e746ae3aed 100644 --- a/Tests/UnitTests/GUI/TestFitParameterModel.h +++ b/Tests/UnitTests/GUI/TestFitParameterModel.h @@ -14,6 +14,7 @@ private slots: void test_InitialState(); void test_addFitParameter(); void test_addFitParameterAndLink(); + void test_addTwoFitParameterAndLinks(); }; inline void TestFitParameterModel::test_InitialState() @@ -189,6 +190,53 @@ inline void TestFitParameterModel::test_addFitParameterAndLink() } +inline void TestFitParameterModel::test_addTwoFitParameterAndLinks() +{ + JobModel source; + SessionItem *fitSuiteItem = source.insertNewItem(Constants::FitSuiteType); + SessionItem *container = source.insertNewItem(Constants::FitParameterContainerType, fitSuiteItem->index(), -1, FitSuiteItem::T_FIT_PARAMETERS); + FitParameterAbsModel proxy(dynamic_cast<FitParameterContainerItem *>(container)); + + // adding fit parameters + SessionItem *fitPar0 = source.insertNewItem(Constants::FitParameterType, container->index()); + SessionItem *link0 = source.insertNewItem(Constants::FitParameterLinkType, fitPar0->index()); + + SessionItem *fitPar1 = source.insertNewItem(Constants::FitParameterType, container->index()); + SessionItem *link1 = source.insertNewItem(Constants::FitParameterLinkType, fitPar1->index()); + + // checking index of root + QCOMPARE(2, proxy.rowCount(QModelIndex())); + QCOMPARE((int)FitParameterAbsModel::MAX_COLUMNS, proxy.columnCount(QModelIndex())); + + // accessing fitPar1 + QModelIndex index1 = proxy.index(1, 0, QModelIndex()); + QCOMPARE(index1.row(), 1); + QCOMPARE(index1.column(), 0); + QCOMPARE(index1.parent(), QModelIndex()); + QCOMPARE(proxy.rowCount(index1), 1); + QCOMPARE(proxy.columnCount(index1), 1); + + QCOMPARE(fitPar1, proxy.itemForIndex(index1)); + QCOMPARE(fitPar1->displayName(), proxy.data(index1).toString()); + QCOMPARE(index1, proxy.indexOfItem(fitPar1)); + + // accessing link1 + QModelIndex linkIndex1 = proxy.index(0, 0, index1); + QCOMPARE(linkIndex1.row(), 0); + QCOMPARE(linkIndex1.column(), 0); + qDebug() << "AAA" << index1 << linkIndex1; + QCOMPARE(linkIndex1.parent(), index1); + QCOMPARE(proxy.rowCount(linkIndex1), 0); + QCOMPARE(proxy.columnCount(linkIndex1), 0); + +// QCOMPARE(proxy.parent(linkIndex), index); +// QCOMPARE(proxy.itemForIndex(linkIndex), link0->getItem(FitParameterLinkItem::P_LINK)); + + +// QModelIndex linkIndex1 = proxy.index(0, 0, index1); + +} + #endif