From 6f43ca3d9f3690d751477afea6496107730d0847 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Fri, 16 Nov 2012 17:46:05 +0100 Subject: [PATCH] finally renamed dataview appropriately; restructured load/save/remove structure for meshes as a prototype for the other widgets --- Gui/DataView/CMakeLists.txt | 4 +- Gui/DataView/MshTabWidget.cpp | 4 +- Gui/DataView/MshTabWidgetBase.ui | 74 +++++++++++++++++++--- Gui/DataView/{DataView.cpp => MshView.cpp} | 61 +++++++++++------- Gui/DataView/{DataView.h => MshView.h} | 16 ++--- 5 files changed, 117 insertions(+), 42 deletions(-) rename Gui/DataView/{DataView.cpp => MshView.cpp} (81%) rename Gui/DataView/{DataView.h => MshView.h} (92%) diff --git a/Gui/DataView/CMakeLists.txt b/Gui/DataView/CMakeLists.txt index c520b4bde93..2b1f32a08fa 100644 --- a/Gui/DataView/CMakeLists.txt +++ b/Gui/DataView/CMakeLists.txt @@ -4,7 +4,6 @@ set( SOURCES ColorTableView.cpp CondFromRasterDialog.cpp ConditionWriterDialog.cpp - DataView.cpp DirectConditionGenerator.cpp ElementTreeModel.cpp FEMConditionSetupDialog.cpp @@ -25,6 +24,7 @@ set( SOURCES MshModel.cpp MshQualitySelectionDialog.cpp MshTabWidget.cpp + MshView.cpp NetCdfConfigureDialog.cpp NewProcessDialog.cpp ProcessModel.cpp @@ -42,7 +42,6 @@ set( MOC_HEADERS ColorTableView.h CondFromRasterDialog.h ConditionWriterDialog.h - DataView.h ElementTreeModel.h FEMConditionSetupDialog.h GEOModels.h @@ -58,6 +57,7 @@ set( MOC_HEADERS MshModel.h MshQualitySelectionDialog.h MshTabWidget.h + MshView.h NetCdfConfigureDialog.h NewProcessDialog.h ProcessModel.h diff --git a/Gui/DataView/MshTabWidget.cpp b/Gui/DataView/MshTabWidget.cpp index a84c4768619..bcaf875c830 100644 --- a/Gui/DataView/MshTabWidget.cpp +++ b/Gui/DataView/MshTabWidget.cpp @@ -18,5 +18,7 @@ MshTabWidget::MshTabWidget( QWidget* parent /*= 0*/ ) setupUi(this); connect(this->addMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(addMeshAction())); - connect(this->clearAllPushButton, SIGNAL(clicked()), this->treeView, SLOT(removeAllMeshes())); + connect(this->saveMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(writeMeshToFile())); + connect(this->removeMeshPushButton, SIGNAL(clicked()), this->treeView, SLOT(removeMesh())); + //connect(this->clearAllPushButton, SIGNAL(clicked()), this->treeView, SLOT(removeAllMeshes())); } diff --git a/Gui/DataView/MshTabWidgetBase.ui b/Gui/DataView/MshTabWidgetBase.ui index b83f93919ab..4cc6999aba6 100644 --- a/Gui/DataView/MshTabWidgetBase.ui +++ b/Gui/DataView/MshTabWidgetBase.ui @@ -17,27 +17,83 @@ <property name="margin"> <number>2</number> </property> - <item> - <widget class="DataView" name="treeView"/> - </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QPushButton" name="addMeshPushButton"> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> <property name="text"> - <string>Add mesh...</string> + <string>Add</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="clearAllPushButton"> + <widget class="QPushButton" name="saveMeshPushButton"> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> <property name="text"> - <string>Remove All</string> + <string>Save</string> </property> </widget> </item> + <item> + <widget class="QPushButton" name="removeMeshPushButton"> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>50</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> </layout> </item> + <item> + <widget class="MshView" name="treeView"/> + </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_2"> <property name="topMargin"> @@ -69,15 +125,15 @@ </layout> </item> <item> - <widget class="DataView" name="elementView"/> + <widget class="MshView" name="elementView"/> </item> </layout> </widget> <customwidgets> <customwidget> - <class>DataView</class> + <class>MshView</class> <extends>QTreeView</extends> - <header>DataView.h</header> + <header>MshView.h</header> </customwidget> </customwidgets> <resources/> diff --git a/Gui/DataView/DataView.cpp b/Gui/DataView/MshView.cpp similarity index 81% rename from Gui/DataView/DataView.cpp rename to Gui/DataView/MshView.cpp index d60a4d7e59f..a56acffb075 100644 --- a/Gui/DataView/DataView.cpp +++ b/Gui/DataView/MshView.cpp @@ -4,12 +4,12 @@ * See accompanying file LICENSE.txt or * http://www.opengeosys.net/LICENSE.txt * - * \file DataView.cpp + * \file MshView.cpp * * Created on 2009-09-24 by Lars Bilke */ -#include "DataView.h" +#include "MshView.h" #include "Mesh.h" #include "MshEditDialog.h" #include "MshItem.h" @@ -29,18 +29,18 @@ #include "RapidXmlIO/RapidVtuInterface.h" #include "Writer.h" // necessary to avoid Linker Error in Windows -DataView::DataView( QWidget* parent /*= 0*/ ) +MshView::MshView( QWidget* parent /*= 0*/ ) : QTreeView(parent) { //resizeColumnsToContents(); //resizeRowsToContents(); } -DataView::~DataView() +MshView::~MshView() { } -void DataView::updateView() +void MshView::updateView() { setAlternatingRowColors(true); setColumnWidth(0,125); @@ -49,37 +49,48 @@ void DataView::updateView() resizeColumnToContents(i); } -void DataView::addMeshAction() +void MshView::addMeshAction() { QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, "Select mesh file", settings.value( "lastOpenedFileDirectory").toString(), - "OpenGeosys mesh files (*.msh);;All files (* *.*)"); + "OpenGeosys mesh files (*.vtu *.msh);;All files (* *.*)"); if (!fileName.isEmpty()) { std::string name = fileName.toStdString(); FileIO::MeshIO meshIO; MeshLib::Mesh* msh = meshIO.loadMeshFromFile(name); if (msh) + { static_cast<MshModel*>(this->model())->addMesh(msh); + QDir dir = QDir(fileName); + settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); + } } } -void DataView::removeMesh() +void MshView::removeMesh() { - emit requestMeshRemoval(this->selectionModel()->currentIndex()); + QModelIndex index (this->selectionModel()->currentIndex()); + if (!index.isValid()) + OGSError::box("No mesh selected."); + else + emit requestMeshRemoval(index); } -void DataView::removeAllMeshes() +/* +// Removed functionality. Do we still need this? +void MshView::removeAllMeshes() { TreeItem* root = static_cast<MshModel*>(this->model())->getItem(QModelIndex()); int nChildren = root->childCount() - 1; for (int i = nChildren; i >= 0; i--) emit requestMeshRemoval(this->model()->index(i, 0, QModelIndex())); } +*/ -void DataView::contextMenuEvent( QContextMenuEvent* event ) +void MshView::contextMenuEvent( QContextMenuEvent* event ) { QModelIndex index = this->selectionModel()->currentIndex(); MshItem* item = dynamic_cast<MshItem*>(static_cast<TreeItem*>(index.internalPointer())); @@ -89,25 +100,25 @@ void DataView::contextMenuEvent( QContextMenuEvent* event ) QMenu menu; QAction* editMeshAction = menu.addAction("Edit mesh..."); QAction* checkMeshAction = menu.addAction("Check mesh quality..."); - QAction* saveMeshAction = menu.addAction("Save mesh..."); + //QAction* saveMeshAction = menu.addAction("Save mesh..."); menu.addSeparator(); QMenu direct_cond_menu("DIRECT Conditions"); menu.addMenu(&direct_cond_menu); QAction* addDirectAction = direct_cond_menu.addAction("Add..."); QAction* loadDirectAction = direct_cond_menu.addAction("Load..."); menu.addSeparator(); - QAction* removeMeshAction = menu.addAction("Remove mesh"); + //QAction* removeMeshAction = menu.addAction("Remove mesh"); connect(editMeshAction, SIGNAL(triggered()), this, SLOT(openMshEditDialog())); connect(checkMeshAction, SIGNAL(triggered()), this, SLOT(checkMeshQuality())); - connect(saveMeshAction, SIGNAL(triggered()), this, SLOT(writeMeshToFile())); + //connect(saveMeshAction, SIGNAL(triggered()), this, SLOT(writeMeshToFile())); connect(addDirectAction, SIGNAL(triggered()), this, SLOT(addDIRECTSourceTerms())); connect(loadDirectAction, SIGNAL(triggered()), this, SLOT(loadDIRECTSourceTerms())); - connect(removeMeshAction, SIGNAL(triggered()), this, SLOT(removeMesh())); + //connect(removeMeshAction, SIGNAL(triggered()), this, SLOT(removeMesh())); menu.exec(event->globalPos()); } } -void DataView::openMshEditDialog() +void MshView::openMshEditDialog() { MshModel* model = static_cast<MshModel*>(this->model()); QModelIndex index = this->selectionModel()->currentIndex(); @@ -120,11 +131,17 @@ void DataView::openMshEditDialog() meshEdit.exec(); } -int DataView::writeMeshToFile() const +int MshView::writeMeshToFile() const { QModelIndex index = this->selectionModel()->currentIndex(); - const MeshLib::Mesh* mesh = - static_cast<MshModel*>(this->model())->getMesh(index); + + if (!index.isValid()) + { + OGSError::box("No mesh selected."); + return 0; + } + + const MeshLib::Mesh* mesh = static_cast<MshModel*>(this->model())->getMesh(index); if (mesh) { @@ -160,7 +177,7 @@ int DataView::writeMeshToFile() const return 0; } -void DataView::addDIRECTSourceTerms() +void MshView::addDIRECTSourceTerms() { QModelIndex index = this->selectionModel()->currentIndex(); const MeshLib::Mesh* grid = static_cast<MshModel*>(this->model())->getMesh(index); @@ -168,7 +185,7 @@ void DataView::addDIRECTSourceTerms() } -void DataView::loadDIRECTSourceTerms() +void MshView::loadDIRECTSourceTerms() { QModelIndex index = this->selectionModel()->currentIndex(); const MeshLib::Mesh* grid = static_cast<MshModel*>(this->model())->getMesh(index); @@ -176,7 +193,7 @@ void DataView::loadDIRECTSourceTerms() // TODO6 emit requestDIRECTSourceTerms(grid->getName(), nodes); } -void DataView::checkMeshQuality () +void MshView::checkMeshQuality () { QModelIndex index = this->selectionModel()->currentIndex(); MshItem* item = static_cast<MshItem*>(static_cast<MshModel*>(this->model())->getItem(index)); diff --git a/Gui/DataView/DataView.h b/Gui/DataView/MshView.h similarity index 92% rename from Gui/DataView/DataView.h rename to Gui/DataView/MshView.h index 333c5a0370d..356437b8b9b 100644 --- a/Gui/DataView/DataView.h +++ b/Gui/DataView/MshView.h @@ -4,12 +4,12 @@ * See accompanying file LICENSE.txt or * http://www.opengeosys.net/LICENSE.txt * - * \file DataView.h + * \file MshView.h * * Created on 2009-09-24 by Lars Bilke */ -#ifndef DATAVIEW_H -#define DATAVIEW_H +#ifndef MSHVIEW_H +#define MSHVIEW_H #include "Point.h" #include "GeoType.h" @@ -30,13 +30,13 @@ namespace MeshLib { * The DataView is table view which acts as a base class for displaying * several OSG data formats. */ -class DataView : public QTreeView +class MshView : public QTreeView { Q_OBJECT public: - DataView(QWidget* parent = 0); - ~DataView(); + MshView(QWidget* parent = 0); + ~MshView(); public slots: void updateView(); @@ -71,7 +71,7 @@ private slots: void removeMesh(); /// Remove all currently loaded meshes. - void removeAllMeshes(); + //void removeAllMeshes(); /// Calls the FileDialog to save a mesh to a file. int writeMeshToFile() const; @@ -95,4 +95,4 @@ signals: const QItemSelection &deselected); */ }; -#endif // DATAVIEW_H +#endif // MSHVIEW_H -- GitLab