Skip to content

Commit

Permalink
drag & drop of the variables effective
Browse files Browse the repository at this point in the history
  • Loading branch information
LafCorentin committed Aug 9, 2020
1 parent 4d0ccae commit 3bd3dfa
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 208 deletions.
49 changes: 24 additions & 25 deletions src/plugins/editing/MappingView/src/mappingvieweditingwidget.cpp
Expand Up @@ -59,7 +59,7 @@ MappingViewEditingModel::MappingViewEditingModel(QObject *pParent) :

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

static const char *MappingViewEdittingMimeType = "opencor/mapping-view-editting";
const char *MappingViewEditingModel::MappingViewEdittingMimeType = "opencor/mapping-view-editting";

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

Expand All @@ -75,24 +75,13 @@ QMimeData * MappingViewEditingModel::mimeData(const QModelIndexList &pIndexes) c
auto res = new QMimeData();
QString names;

// Retrieve the URL of the different file (not folder) items
// Note: this list of URLs is useful with regards to the FileSystemMimeType
// MIME type on which external widgets (e.g. the central widget) rely
// on to extract the name of the vavarious files the MIME data
// contains
//TODO block dragging of multiple elements;

for (const auto &index : pIndexes) {
names.append(" "+itemFromIndex(index)->text());
names.append(itemFromIndex(index)->text()+"|"+itemFromIndex(index)->accessibleDescription());
}

res->setText(names);

// Set the data that contains information on both the folder and file items
// Note: this data is useful with regards to the FileOrganiserWindowMimeType
// MIME type on which the file organiser widget relies for moving
// folder and file items around

//res->setData(MappingViewEdittingMimeType, encodeData(pIndexes));
res->setData(MappingViewEdittingMimeType,names.toUtf8());

return res;
}
Expand Down Expand Up @@ -152,6 +141,9 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,
mVariableTree = new QTreeView(this);
mVariableTree->setDragEnabled(true);

mVariableTreeModel = new MappingViewEditingModel();
mVariableTree->setModel(mVariableTreeModel);

mHorizontalSplitterWidget->addWidget(mVariableTree);

// Keep track of our movement
Expand All @@ -164,10 +156,8 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,

// add a Zinc widget

mZincWidget = new MappingViewZincWidget(this, mMeshFileName);
mZincWidget = new MappingViewZincWidget(this, mMeshFileName, this);

connect(mZincWidget, &MappingViewZincWidget::nodeSelection,
this, &MappingViewEditingWidget::nodeSelection);
connect(mDelayWidget, &QwtWheel::valueChanged,
mZincWidget, &MappingViewZincWidget::setNodeSizes );

Expand Down Expand Up @@ -210,6 +200,16 @@ void MappingViewEditingWidget::retranslateUi()

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

void MappingViewEditingWidget::setNodeValue(const int pId, const QString &pVariable)
{
if (pId!=-1) {
mMapMatch.insert(pId,pVariable);
selectNode(pId);
}
}

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

void MappingViewEditingWidget::filePermissionsChanged()
{
}
Expand All @@ -218,7 +218,7 @@ void MappingViewEditingWidget::filePermissionsChanged()

bool MappingViewEditingWidget::setMeshFile(const QString &pFileName, bool pShowWarning)
{
//TODO warinings ?
//TODO warnings ?
Q_UNUSED(pShowWarning)

mMeshFileName = pFileName;
Expand All @@ -240,7 +240,7 @@ void MappingViewEditingWidget::populateTree()
return;
}

QStandardItemModel *treeModel = new MappingViewEditingModel();
mVariableTreeModel->clear();

// Retrieve the model's components

Expand All @@ -263,7 +263,7 @@ void MappingViewEditingWidget::populateTree()

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

treeModel->invisibleRootItem()->appendRow(componentItem);
mVariableTreeModel->invisibleRootItem()->appendRow(componentItem);

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

Expand All @@ -272,15 +272,14 @@ void MappingViewEditingWidget::populateTree()
for (ObjRef<iface::cellml_api::CellMLVariable> componentVariable = componentVariablesIter->nextVariable();
componentVariable != nullptr; componentVariable = componentVariablesIter->nextVariable()) {

QStandardItem *variableItem = new QStandardItem(QString::fromStdWString(component->name())+"/"+QString::fromStdWString(componentVariable->name()));
QStandardItem *variableItem = new QStandardItem(QString::fromStdWString(componentVariable->name()));
variableItem->setAccessibleDescription(QString::fromStdWString(component->name()));

componentItem->appendRow(variableItem);
}
}
}
}

mVariableTree->setModel(treeModel);
}

//==============================================================================
Expand Down Expand Up @@ -317,7 +316,7 @@ void MappingViewEditingWidget::emitVerticalSplitterMoved()

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

void MappingViewEditingWidget::nodeSelection(int pId)
void MappingViewEditingWidget::selectNode(int pId)
{
if (pId==-1) {
mNodeValue->setText("");
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/editing/MappingView/src/mappingvieweditingwidget.h
Expand Up @@ -65,19 +65,21 @@ namespace MappingView {

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


class MappingViewEditingModel : public QStandardItemModel
{
Q_OBJECT

public:
static const char *MappingViewEdittingMimeType;

explicit MappingViewEditingModel(QObject *pParent = nullptr);

QStringList mimeTypes() const override;
QMimeData * mimeData(const QModelIndexList &pIndexes) const override;

};


class MappingViewEditingWidget : public Core::Widget
{
Q_OBJECT
Expand All @@ -89,6 +91,9 @@ class MappingViewEditingWidget : public Core::Widget

void retranslateUi() override;

void selectNode(int pId);
void setNodeValue(const int pId, const QString &pVariable);

void filePermissionsChanged();

bool setMeshFile(const QString &pFileName, bool pShowWarning = true);
Expand All @@ -107,6 +112,8 @@ class MappingViewEditingWidget : public Core::Widget
QLabel *mVariableValue;
QTreeView *mVariableTree;

MappingViewEditingModel *mVariableTreeModel;

QString mMeshFileName;

CellMLSupport::CellmlFile *mCellmlFile;
Expand All @@ -123,7 +130,6 @@ class MappingViewEditingWidget : public Core::Widget
private slots:
void emitHorizontalSplitterMoved();
void emitVerticalSplitterMoved();
void nodeSelection(int pId);
};

//==============================================================================
Expand Down
11 changes: 7 additions & 4 deletions src/plugins/editing/MappingView/src/mappingviewwidget.cpp
Expand Up @@ -206,6 +206,7 @@ void MappingViewWidget::dragEnterEvent(QDragEnterEvent *pEvent)
//TODO
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
acceptEvent = true;
qDebug("drop of %s accepted",qPrintable(fileName));
}
}

Expand All @@ -232,13 +233,15 @@ void MappingViewWidget::dropEvent(QDropEvent *pEvent)
// Import/open the one or several files

for (const auto &fileName : Core::droppedFileNames(pEvent)) {
if (mFileTypeInterfaces.contains(fileName)) {
//import(fileName); //?
//TODO
} else if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
qDebug(">>> open %s !",qPrintable(fileName));
mEditingWidget->setMeshFile(fileName);
mMeshFileName = fileName;
} else if (mFileTypeInterfaces.contains(fileName)) {
//import(fileName); //?
//TODO
} else {
qDebug(">>> send %s to opencor to open it !",qPrintable(fileName));
QDesktopServices::openUrl("opencor://openFile/"+fileName);
}
}
Expand Down

0 comments on commit 3bd3dfa

Please sign in to comment.