Skip to content

Commit

Permalink
return to .ui + var tree + light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
LafCorentin committed Aug 3, 2020
1 parent aab0008 commit b163409
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 125 deletions.
2 changes: 2 additions & 0 deletions src/plugins/editing/MappingView/CMakeLists.txt
Expand Up @@ -15,6 +15,8 @@ add_plugin(MappingView
src/mappingviewplugin.cpp
src/mappingviewwidget.cpp
src/mappingviewzincwidget.cpp
UIS
src/mappingviewwidget.ui
PLUGINS
Core
CellMLSupport
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/editing/MappingView/i18n/MappingView_fr.ts
@@ -1,6 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="fr_FR" sourcelanguage="en_GB">
<context>
<name>MappingViewWidget</name>
<message>
<source>Node:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Variable:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OpenCOR::MappingView::MappingViewPlugin</name>
<message>
Expand Down
34 changes: 33 additions & 1 deletion src/plugins/editing/MappingView/src/mappingvieweditingwidget.cpp
Expand Up @@ -46,13 +46,16 @@ namespace MappingView {
MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,
const QString &pMeshFileName,
QWidget *pParent) :
Core::SplitterWidget(pParent)
Core::SplitterWidget(pParent),
mMapMatch()
{
mCellmlFile = CellMLSupport::CellmlFileManager::instance()->cellmlFile(pFileName);

mListViewModelVariables = new QStringListModel();
mListViewModelOutput = new QStringListModel();

mTreeViewModel = new QStandardItemModel(this);

populateCellmlModel();
populateOutput(pMeshFileName);
}
Expand Down Expand Up @@ -87,6 +90,11 @@ QStringListModel* MappingViewEditingWidget::listViewModelOutput()
return mListViewModelOutput;
}

QStandardItemModel *MappingViewEditingWidget::getTreeViewModel()
{
return mTreeViewModel;
}

//==============================================================================

void MappingViewEditingWidget::filePermissionsChanged()
Expand All @@ -95,6 +103,23 @@ void MappingViewEditingWidget::filePermissionsChanged()

//==============================================================================

QString MappingViewEditingWidget::getVariableOfNode(int pNodeId)
{
if (mMapMatch.contains(pNodeId)) {
return mMapMatch[pNodeId];
}
return "";
}

//==============================================================================

void MappingViewEditingWidget::AddVariableToNode(QString pVariable, int pNodeId)
{
mMapMatch.insert(pNodeId,pVariable);
}

//==============================================================================

void MappingViewEditingWidget::populateCellmlModel()
{
QStringList list;
Expand Down Expand Up @@ -125,13 +150,20 @@ void MappingViewEditingWidget::populateCellmlModel()
ObjRef<iface::cellml_api::CellMLVariableSet> componentVariables = component->variables();

if (componentVariables->length() != 0) {

QStandardItem *componentItem = new QStandardItem(QString::fromStdWString(component->name()));
mTreeViewModel->invisibleRootItem()->appendRow(componentItem);

// Retrieve the model's component's variables themselves

ObjRef<iface::cellml_api::CellMLVariableIterator> componentVariablesIter = componentVariables->iterateVariables();

for (ObjRef<iface::cellml_api::CellMLVariable> componentVariable = componentVariablesIter->nextVariable();
componentVariable != nullptr; componentVariable = componentVariablesIter->nextVariable()) {

QStandardItem *variableItem = new QStandardItem(QString::fromStdWString(componentVariable->name()));

componentItem->appendRow(variableItem);
list.append(QString::fromStdWString(componentVariable->name()));
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/editing/MappingView/src/mappingvieweditingwidget.h
Expand Up @@ -33,6 +33,7 @@ along with this program. If not, see <https://gnu.org/licenses>.

#include <QStringListModel> //TODO remove when over
#include <QTableView>
#include <QStandardItemModel>

//==============================================================================

Expand Down Expand Up @@ -65,12 +66,23 @@ class MappingViewEditingWidget : public Core::SplitterWidget

QStringListModel *listViewModelOutput();

QStandardItemModel *getTreeViewModel();

void filePermissionsChanged();

QString getVariableOfNode(int pNodeId);

void AddVariableToNode(QString pVariable, int pNodeId);

private:

CellMLSupport::CellmlFile *mCellmlFile;

//TODO : * or not ?
QMap<int, QString> mMapMatch;

QStandardItemModel *mTreeViewModel;

QStringListModel
*mListViewModelVariables = nullptr,//TODO temporary
*mListViewModelOutput = nullptr;//TODO temporary
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/editing/MappingView/src/mappingviewmeshreader.cpp
Expand Up @@ -34,8 +34,8 @@ namespace MappingView {

//==============================================================================

MappingViewMeshReader::MappingViewMeshReader(QString name):
pFileName(name)
MappingViewMeshReader::MappingViewMeshReader(QString pName):
pFileName(pName)
{
}

Expand Down
Expand Up @@ -44,7 +44,7 @@ class MappingViewMeshReader : public QObject
Q_OBJECT
public:

MappingViewMeshReader(QString);
MappingViewMeshReader(QString pFileName);

QStringList getNodesNames();

Expand Down
47 changes: 32 additions & 15 deletions src/plugins/editing/MappingView/src/mappingviewwidget.cpp
Expand Up @@ -24,6 +24,7 @@ along with this program. If not, see <https://gnu.org/licenses>.
#include "borderedwidget.h"
#include "mappingviewwidget.h"
#include "zincwidget.h"
#include "toolbarwidget.h"

//==============================================================================

Expand Down Expand Up @@ -52,26 +53,20 @@ namespace MappingView {

MappingViewWidget::MappingViewWidget(QWidget *pParent) :
Core::SplitterWidget(pParent),
mAxesFontPointSize(0)
mAxesFontPointSize(0),
mGui(new Ui::MappingViewWidget)
{

// Set up the GUI

mGui->setupUi(this);

// Keep track of our movement
/*
connect(this, &Core::SplitterWidget::splitterMoved,
this, &MappingViewEditingWidget::splitterMoved);
*/

// Set our orientation

setOrientation(Qt::Vertical);




mListWidgetVariables = new QListWidget();
mListWidgetOutput = new QListWidget();


//addWidget(mListWidgetVariables);

//TODO
Expand All @@ -82,10 +77,18 @@ MappingViewWidget::MappingViewWidget(QWidget *pParent) :
mMappingViewZincWidget = new MappingViewZincWidget(this, mMeshFileName);

//TODO move to mappingviewzincwidget and you know how it works
connect(mMappingViewZincWidget, SIGNAL(devicePixelRatioChanged(const int &)),
this, SLOT(devicePixelRatioChanged(const int &)));
connect(mMappingViewZincWidget, &MappingViewZincWidget::devicePixelRatioChanged,
this, &MappingViewWidget::devicePixelRatioChanged);

connect(mMappingViewZincWidget, &MappingViewZincWidget::nodeSelection,
this, &MappingViewWidget::nodeSelection);

mGui->layout->addWidget(mMappingViewZincWidget);

//mToolBarWidget = new Core::ToolBarWidget();



addWidget(mMappingViewZincWidget);
}

//==============================================================================
Expand Down Expand Up @@ -124,6 +127,7 @@ void MappingViewWidget::initialize(const QString &pFileName)

//mListWidgetVariables->setModel(mEditingWidget->listViewModelVariables()); //TODO set only when charging the plugin ?
//mGui->outputList->setModel(mEditingWidget->listViewModelOutput());
mGui->variableTree->setModel(mEditingWidget->getTreeViewModel());
}

//==============================================================================
Expand Down Expand Up @@ -215,6 +219,19 @@ void MappingViewWidget::devicePixelRatioChanged(const int &pDevicePixelRatio)

//==============================================================================

void MappingViewWidget::nodeSelection(int pId) {

if (pId==-1) {
mGui->nodeValue->setText("");
mGui->variableValue->setText("");
} else {
mGui->nodeValue->setNum(pId);
mGui->variableValue->setText(mEditingWidget->getVariableOfNode(pId));
}
}

//==============================================================================

} // namespace MappingView
} // namespace OpenCOR

Expand Down
12 changes: 12 additions & 0 deletions src/plugins/editing/MappingView/src/mappingviewwidget.h
Expand Up @@ -49,6 +49,12 @@ namespace OpenCOR {

//==============================================================================

namespace Core {
class ToolBarWidget;
} // namespace Core

//==============================================================================

namespace ZincWidget {
class ZincWidget;
} // namespace ZincWidget
Expand Down Expand Up @@ -82,6 +88,10 @@ class MappingViewWidget : public Core::SplitterWidget
int mAxesFontPointSize;

private:
Ui::MappingViewWidget *mGui;

Core::ToolBarWidget *mToolBarWidget;

MappingViewZincWidget *mMappingViewZincWidget;

QListWidget *mListWidgetVariables;
Expand All @@ -94,6 +104,8 @@ class MappingViewWidget : public Core::SplitterWidget

private slots:
void devicePixelRatioChanged(const int &pDevicePixelRatio);
void nodeSelection(int pId);


};

Expand Down

0 comments on commit b163409

Please sign in to comment.