diff --git a/GUI/coregui/Models/FitModelHelper.cpp b/GUI/coregui/Models/FitModelHelper.cpp index fdf49a4b8a012b8e278a79af9f5ef73cfa7c18fb..a4d2e45c97e002080a425645e3e2bf852f677aec 100644 --- a/GUI/coregui/Models/FitModelHelper.cpp +++ b/GUI/coregui/Models/FitModelHelper.cpp @@ -23,6 +23,7 @@ //! Creates fit parameter from given ParameterItem, sets starting value to the value //! of ParameterItem, copies link. + void FitModelHelper::createFitParameter(FitParameterContainerItem *container, ParameterItem *parameterItem) { Q_ASSERT(container); @@ -47,6 +48,7 @@ void FitModelHelper::createFitParameter(FitParameterContainerItem *container, Pa } //! Removes link to given parameterItem from fit parameters + void FitModelHelper::removeFromFitParameters(FitParameterContainerItem *container, ParameterItem *parameterItem) { FitParameterItem *fitParItem = getFitParameterItem(container, parameterItem); @@ -63,6 +65,7 @@ void FitModelHelper::removeFromFitParameters(FitParameterContainerItem *containe //! Adds given parameterItem to the existing fit parameter with display name fitParName. //! If parameterItem is already linked with another fitParameter, it will be relinked + void FitModelHelper::addToFitParameter(FitParameterContainerItem *container, ParameterItem *parameterItem, const QString &fitParName) { Q_ASSERT(container); @@ -78,6 +81,7 @@ void FitModelHelper::addToFitParameter(FitParameterContainerItem *container, Par } //! Returns fFitParameterItem corresponding to given ParameterItem + FitParameterItem *FitModelHelper::getFitParameterItem(FitParameterContainerItem *container, ParameterItem *parameterItem) { Q_ASSERT(container); @@ -85,6 +89,7 @@ FitParameterItem *FitModelHelper::getFitParameterItem(FitParameterContainerItem } //! Returns list of fit parameter display names + QStringList FitModelHelper::getFitParameterNames(FitParameterContainerItem *container) { Q_ASSERT(container); @@ -96,6 +101,7 @@ QStringList FitModelHelper::getFitParameterNames(FitParameterContainerItem *cont } //! return path to given item in the ParameterTreeContainer + QString FitModelHelper::getParameterItemPath(ParameterItem *parameterItem) { QString result = ModelPath::getPathFromIndex(parameterItem->index()); @@ -104,3 +110,19 @@ QString FitModelHelper::getParameterItemPath(ParameterItem *parameterItem) result = result.mid(containerEnd); return result; } + +//! Returns ParameterItem corresponding to given link. +//! Link is relative to ParameterContainerItem, so first we have to find it + +ParameterItem *FitModelHelper::getParameterItem(FitParameterContainerItem *container, const QString &link) +{ + SessionItem *cur = container; + while (cur && cur->modelType() != Constants::JobItemType) { + cur = cur->parent(); + } + Q_ASSERT(cur->modelType() == Constants::JobItemType); + JobItem *jobItem = dynamic_cast<JobItem *>(cur); + Q_ASSERT(jobItem); + return dynamic_cast<ParameterItem *>(ModelPath::getItemFromPath(link, jobItem->parameterContainerItem())); +} + diff --git a/GUI/coregui/Models/FitModelHelper.h b/GUI/coregui/Models/FitModelHelper.h index 4484f77f9f56f3d068cb1f9dddb3d8d8a4875b7a..08beb4ed0ffcb8f17e42d2d89fd471dda382ea00 100644 --- a/GUI/coregui/Models/FitModelHelper.h +++ b/GUI/coregui/Models/FitModelHelper.h @@ -39,7 +39,7 @@ public: static FitParameterItem *getFitParameterItem(FitParameterContainerItem *container, ParameterItem *parameterItem); static QStringList getFitParameterNames(FitParameterContainerItem *container); static QString getParameterItemPath(ParameterItem *parameterItem); - + static ParameterItem *getParameterItem(FitParameterContainerItem *container, const QString &link); }; diff --git a/GUI/coregui/Models/FitParameterAbsModel.cpp b/GUI/coregui/Models/FitParameterAbsModel.cpp index ba97395a78854b1df87cc63db69ee4d29704644c..b1a3d328eaee6bfe8fbfd3fa9be0b18c6efb2869 100644 --- a/GUI/coregui/Models/FitParameterAbsModel.cpp +++ b/GUI/coregui/Models/FitParameterAbsModel.cpp @@ -19,6 +19,8 @@ #include "FitParameterItems.h" #include "SessionModel.h" #include "JobModel.h" +#include "FitModelHelper.h" +#include "ParameterTreeItems.h" #include <QColor> #include <QMimeData> #include <QDebug> @@ -264,6 +266,17 @@ bool FitParameterAbsModel::dropMimeData(const QMimeData *data, Qt::DropAction ac qDebug() << "FitParameterAbsModel::dropMimeData row:" << row << "column:" << column << "parent:" << parent << "mime:" << QString::fromLatin1(data->data(MIME_TYPE)); + if(parent.isValid()) { + if(SessionItem *fitParItem = itemForIndex(parent)) { + Q_ASSERT(fitParItem->modelType() == Constants::FitParameterType); + ParameterItem *parItem = FitModelHelper::getParameterItem(m_root_item, QString::fromLatin1(data->data(MIME_TYPE))); + Q_ASSERT(parItem); + FitModelHelper::addToFitParameter(m_root_item, parItem, fitParItem->displayName()); + qDebug() << "AAAA" << parItem->getItemValue(ParameterItem::P_LINK); + } + } + + return true; } diff --git a/GUI/coregui/Views/FitWidgets/FitParametersWidget.cpp b/GUI/coregui/Views/FitWidgets/FitParametersWidget.cpp index 3778d2a20a82393ff736de513d2f39da36a8726c..f3095a8324337962a0808fd7ee6ea49b914deeee 100644 --- a/GUI/coregui/Views/FitWidgets/FitParametersWidget.cpp +++ b/GUI/coregui/Views/FitWidgets/FitParametersWidget.cpp @@ -334,9 +334,16 @@ void FitParametersWidget::init_job_item() // m_fitParameterModel.reset(new FitParameterModel(parsContainerItem)); // m_fitParameterModel.reset(new FitParameterAbsModel(m_jobItem->fitParameterContainerItem())); + delete m_fitParameterModel; m_fitParameterModel = new FitParameterAbsModel(m_jobItem->fitParameterContainerItem(), m_jobItem->fitParameterContainerItem()->model()); m_treeView->setModel(m_fitParameterModel); + connect(m_fitParameterModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), + this, SLOT(spanParameters())); + +// connect(m_fitParameterModel, SIGNAL(rowsInserted(QModelIndex,int,int)), +// this, SLOT(spanParameters())); + // m_fitParameterModel->createFitParameter(); spanParameters(); diff --git a/GUI/coregui/Views/FitWidgets/FitParametersWidget.h b/GUI/coregui/Views/FitWidgets/FitParametersWidget.h index 26cb265cdeac7e377aaec85f4880c4d749c16f74..4a8d08bef0bb62ee8bf083356ad3bdcbe6b06c31 100644 --- a/GUI/coregui/Views/FitWidgets/FitParametersWidget.h +++ b/GUI/coregui/Views/FitWidgets/FitParametersWidget.h @@ -60,6 +60,7 @@ private slots: void onRemoveFromFitParAction(); void onRemoveFitParAction(); void onAddToFitParAction(int ipar); + void spanParameters(); protected: void contextMenuEvent(QContextMenuEvent *event); @@ -71,7 +72,6 @@ private: void stop_tracking_job_item(); void init_job_item(); - void spanParameters(); bool isCreateFitParameterPossible(); void setActionsEnabled(bool value); void connectTuningWidgetSelection(bool active);