From a1a326e536af534a2f7c86fedd5fb0552e4fcd56 Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Sun, 2 Aug 2020 11:12:14 +0200 Subject: [PATCH] moving meshlab settings classes --- src/meshlab/CMakeLists.txt | 6 +- src/meshlab/mainwindow_Init.cpp | 2 +- src/meshlab/mainwindow_RunTime.cpp | 4 +- src/meshlab/meshlab.pro | 6 +- .../meshlabsettingsdialog.cpp} | 110 +++-------------- .../meshlab_settings/meshlabsettingsdialog.h | 57 +++++++++ .../meshlab_settings/settingdialog.cpp | 111 ++++++++++++++++++ .../settingdialog.h} | 42 ++----- 8 files changed, 206 insertions(+), 132 deletions(-) rename src/meshlab/{customDialog.cpp => meshlab_settings/meshlabsettingsdialog.cpp} (65%) create mode 100644 src/meshlab/meshlab_settings/meshlabsettingsdialog.h create mode 100644 src/meshlab/meshlab_settings/settingdialog.cpp rename src/meshlab/{customDialog.h => meshlab_settings/settingdialog.h} (67%) diff --git a/src/meshlab/CMakeLists.txt b/src/meshlab/CMakeLists.txt index 2109f8f11..ffc693ce4 100644 --- a/src/meshlab/CMakeLists.txt +++ b/src/meshlab/CMakeLists.txt @@ -8,7 +8,6 @@ set(SOURCES additionalgui.cpp changetexturename.cpp - customDialog.cpp filterScriptDialog.cpp glarea.cpp glarea_setting.cpp @@ -27,6 +26,8 @@ set(SOURCES meshlab_settings/richparameterlistdialog.cpp meshlab_settings/richparameterlistframe.cpp meshlab_settings/richparameterwidgets.cpp + meshlab_settings/settingdialog.cpp + meshlab_settings/meshlabsettingsdialog.cpp ${VCGDIR}/wrap/gui/trackball.cpp ${VCGDIR}/wrap/gui/trackmode.cpp ${VCGDIR}/wrap/gui/coordinateframe.cpp) @@ -34,7 +35,6 @@ set(SOURCES set(HEADERS additionalgui.h changetexturename.h - customDialog.h filterScriptDialog.h glarea.h glarea_setting.h @@ -53,6 +53,8 @@ set(HEADERS meshlab_settings/richparameterlistdialog.h meshlab_settings/richparameterlistframe.h meshlab_settings/richparameterwidgets.h + meshlab_settings/settingdialog.h + meshlab_settings/meshlabsettingsdialog.h ${VCGDIR}/wrap/gui/trackball.h ${VCGDIR}/wrap/gui/trackmode.h ${VCGDIR}/wrap/gl/trimesh.h) diff --git a/src/meshlab/mainwindow_Init.cpp b/src/meshlab/mainwindow_Init.cpp index 2f1f1dd65..e17ad8bee 100644 --- a/src/meshlab/mainwindow_Init.cpp +++ b/src/meshlab/mainwindow_Init.cpp @@ -41,7 +41,7 @@ #include #include "mainwindow.h" #include "plugindialog.h" -#include "customDialog.h" +#include "meshlab_settings/meshlabsettingsdialog.h" #include "saveSnapshotDialog.h" #include "ui_congratsDialog.h" diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index 79875d79d..aaad95ff7 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -26,7 +26,7 @@ #include "mainwindow.h" #include "plugindialog.h" #include "filterScriptDialog.h" -#include "customDialog.h" +#include "meshlab_settings/meshlabsettingsdialog.h" #include "saveSnapshotDialog.h" #include "ui_aboutDialog.h" #include "savemaskexporter.h" @@ -2686,7 +2686,7 @@ void MainWindow::showLayerDlg(bool visible) void MainWindow::setCustomize() { - CustomDialog dialog(currentGlobalParams,defaultGlobalParams, this); + MeshLabSettingsDialog dialog(currentGlobalParams,defaultGlobalParams, this); connect(&dialog,SIGNAL(applyCustomSetting()),this,SLOT(updateCustomSettings())); dialog.exec(); } diff --git a/src/meshlab/meshlab.pro b/src/meshlab/meshlab.pro index ea339ab32..b44ba6e9a 100644 --- a/src/meshlab/meshlab.pro +++ b/src/meshlab/meshlab.pro @@ -31,10 +31,11 @@ HEADERS += \ ../common/interfaces.h \ mainwindow.h \ glarea.h \ + meshlab_settings/meshlabsettingsdialog.h \ + meshlab_settings/settingdialog.h \ multiViewer_Container.h \ glarea_setting.h \ plugindialog.h \ - customDialog.h \ filterScriptDialog.h \ saveSnapshotDialog.h \ savemaskexporter.h \ @@ -58,9 +59,10 @@ SOURCES += \ mainwindow_Init.cpp \ mainwindow_RunTime.cpp \ glarea.cpp \ + meshlab_settings/meshlabsettingsdialog.cpp \ + meshlab_settings/settingdialog.cpp \ multiViewer_Container.cpp \ plugindialog.cpp \ - customDialog.cpp \ filterScriptDialog.cpp \ saveSnapshotDialog.cpp \ layerDialog.cpp \ diff --git a/src/meshlab/customDialog.cpp b/src/meshlab/meshlab_settings/meshlabsettingsdialog.cpp similarity index 65% rename from src/meshlab/customDialog.cpp rename to src/meshlab/meshlab_settings/meshlabsettingsdialog.cpp index 1186f8047..4c7be3598 100644 --- a/src/meshlab/customDialog.cpp +++ b/src/meshlab/meshlab_settings/meshlabsettingsdialog.cpp @@ -1,14 +1,14 @@ /**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * +* VCGLib o o * +* Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2005 \/)\/ * +* Copyright(C) 2004-2020 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -21,13 +21,16 @@ * * ****************************************************************************/ -#include -#include "customDialog.h" -#include - #include +#include "meshlabsettingsdialog.h" + +#include "settingdialog.h" + +#include + + using namespace vcg; -CustomDialog::CustomDialog(RichParameterList& curparset, RichParameterList& defparset, QWidget * parent) +MeshLabSettingsDialog::MeshLabSettingsDialog(RichParameterList& curparset, RichParameterList& defparset, QWidget * parent) :QDialog(parent),curParSet(curparset),defParSet(defparset) { setModal(false); @@ -46,7 +49,7 @@ CustomDialog::CustomDialog(RichParameterList& curparset, RichParameterList& defp this->setWindowTitle(tr("Global Parameters Window")); } -void CustomDialog::openSubDialog( QTableWidgetItem* itm ) +void MeshLabSettingsDialog::openSubDialog( QTableWidgetItem* itm ) { int rprow = tw->row(itm); RichParameter *defPar = defParSet.findParameter(vrp[rprow]->name()); @@ -57,11 +60,11 @@ void CustomDialog::openSubDialog( QTableWidgetItem* itm ) delete setdial; } -CustomDialog::~CustomDialog() +MeshLabSettingsDialog::~MeshLabSettingsDialog() { } -void CustomDialog::updateSettings() +void MeshLabSettingsDialog::updateSettings() { QStringList slst; slst.push_back("Variable Name"); @@ -73,9 +76,9 @@ void CustomDialog::updateSettings() tw->verticalHeader()->hide(); tw->setSelectionBehavior(QAbstractItemView::SelectRows); - + //tw->horizontalHeader()->setResizeMode(tw->columnCount() - 1, QHeaderView::Stretch); - + //int sz = tw->font().pointSize(); int ii = 0; for(RichParameter* p : curParSet) @@ -106,7 +109,7 @@ void CustomDialog::updateSettings() emit tw->horizontalHeader()->sectionAutoResize( 1,QHeaderView::ResizeToContents);*/ } -QTableWidgetItem* CustomDialog::createQTableWidgetItemFromRichParameter(const RichParameter& pd) +QTableWidgetItem* MeshLabSettingsDialog::createQTableWidgetItemFromRichParameter(const RichParameter& pd) { if (pd.value().isAbsPerc()){ return new QTableWidgetItem(QString::number(pd.value().getAbsPerc())); @@ -168,80 +171,3 @@ QTableWidgetItem* CustomDialog::createQTableWidgetItemFromRichParameter(const Ri return nullptr; } } - -//Maybe a MeshDocument parameter is needed. See loadFrameContent definition - -/*WARNING!*******************************************************/ -//In defPar->defVal the hardwired value is memorized -//in curPar->defVal the one in the sys reg -/****************************************************************/ - -SettingDialog::SettingDialog(RichParameter* currentPar, const RichParameter* defaultPar, QWidget* parent /*= 0*/ ) -:QDialog(parent),frame(this),curPar(currentPar),defPar(defaultPar),tmppar(NULL) -{ - setModal(true); - savebut = new QPushButton("Save",this); - resetbut = new QPushButton("Reset",this); - applybut = new QPushButton("Apply",this); - loadbut = new QPushButton("Load",this); - closebut = new QPushButton("Close",this); - - QGridLayout* dialoglayout = new QGridLayout(parent); - - dialoglayout->addWidget(savebut,1,0); - dialoglayout->addWidget(resetbut,1,1); - dialoglayout->addWidget(loadbut,1,2); - dialoglayout->addWidget(applybut,1,3); - dialoglayout->addWidget(closebut,1,4); - - RichParameterList tmpParSet; - tmppar = tmpParSet.addParam(*curPar); - frame.loadFrameContent(tmpParSet); - dialoglayout->addWidget(&frame,0,0,1,5); - dialoglayout->setSizeConstraint(QLayout::SetFixedSize); - setLayout(dialoglayout); - connect(applybut,SIGNAL(clicked()),this,SLOT(apply())); - connect(resetbut,SIGNAL(clicked()),this,SLOT(reset())); - connect(savebut,SIGNAL(clicked()),this,SLOT(save())); - connect(loadbut,SIGNAL(clicked()),this,SLOT(load())); - connect(closebut,SIGNAL(clicked()),this,SLOT(close())); -} - -void SettingDialog::save() -{ - apply(); - QDomDocument doc("MeshLabSettings"); - doc.appendChild(tmppar->fillToXMLDocument(doc)); - QString docstring = doc.toString(); - qDebug("Writing into Settings param with name %s and content ****%s****", qUtf8Printable(tmppar->name()), qUtf8Printable(docstring)); - QSettings setting; - setting.setValue(tmppar->name(),QVariant(docstring)); - curPar->value().set(tmppar->value()); -} - -void SettingDialog::apply() -{ - assert(frame.stdfieldwidgets.size() == 1); - frame.stdfieldwidgets.at(0)->collectWidgetValue(); - curPar->value().set(tmppar->value()); - emit applySettingSignal(); -} - -void SettingDialog::reset() -{ - qDebug("resetting the value of param %s to the hardwired default", qUtf8Printable(curPar->name())); - tmppar->value().set(defPar->value()); - assert(frame.stdfieldwidgets.size() == 1); - frame.stdfieldwidgets.at(0)->setWidgetValue(tmppar->value()); - apply(); -} - -void SettingDialog::load() -{ - assert(frame.stdfieldwidgets.size() == 1); - frame.stdfieldwidgets.at(0)->setWidgetValue(curPar->value()); -} - -SettingDialog::~SettingDialog() -{ -} diff --git a/src/meshlab/meshlab_settings/meshlabsettingsdialog.h b/src/meshlab/meshlab_settings/meshlabsettingsdialog.h new file mode 100644 index 000000000..ee4f21b80 --- /dev/null +++ b/src/meshlab/meshlab_settings/meshlabsettingsdialog.h @@ -0,0 +1,57 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2020 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ + +#ifndef MESHLABSETTINGSDIALOG_H +#define MESHLABSETTINGSDIALOG_H + +#include +#include +#include + + +class MeshLabSettingsDialog : public QDialog +{ +Q_OBJECT +public: + MeshLabSettingsDialog(RichParameterList& parset,RichParameterList& defparset,QWidget *parent = 0); + ~MeshLabSettingsDialog(); + //void loadCurrentSetting(RichParameterSet& parset); + +public slots: + void openSubDialog(QTableWidgetItem* itm); + void updateSettings(); +signals: + void applyCustomSetting(); + +private: + RichParameterList& curParSet; + RichParameterList& defParSet; + QTableWidget* tw; + QVector vrp; + void dispatch(const RichParameter& par); + QPushButton* closebut; + + static QTableWidgetItem* createQTableWidgetItemFromRichParameter(const RichParameter& pd); +}; + +#endif // MESHLABSETTINGSDIALOG_H diff --git a/src/meshlab/meshlab_settings/settingdialog.cpp b/src/meshlab/meshlab_settings/settingdialog.cpp new file mode 100644 index 000000000..dabc4ec27 --- /dev/null +++ b/src/meshlab/meshlab_settings/settingdialog.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2020 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ + +#include "settingdialog.h" + +//Maybe a MeshDocument parameter is needed. See loadFrameContent definition + +/*WARNING!*******************************************************/ +//In defPar->defVal the hardwired value is memorized +//in curPar->defVal the one in the sys reg +/****************************************************************/ + +SettingDialog::SettingDialog( + RichParameter* currentPar, + const RichParameter* defaultPar, + QWidget* parent) : + QDialog(parent), + frame(this), + curPar(currentPar), + defPar(defaultPar), + tmppar(NULL) +{ + setModal(true); + savebut = new QPushButton("Save",this); + resetbut = new QPushButton("Reset",this); + applybut = new QPushButton("Apply",this); + loadbut = new QPushButton("Load",this); + closebut = new QPushButton("Close",this); + + QGridLayout* dialoglayout = new QGridLayout(parent); + + dialoglayout->addWidget(savebut,1,0); + dialoglayout->addWidget(resetbut,1,1); + dialoglayout->addWidget(loadbut,1,2); + dialoglayout->addWidget(applybut,1,3); + dialoglayout->addWidget(closebut,1,4); + + RichParameterList tmpParSet; + tmppar = tmpParSet.addParam(*curPar); + frame.loadFrameContent(tmpParSet); + dialoglayout->addWidget(&frame,0,0,1,5); + dialoglayout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(dialoglayout); + + connect(applybut,SIGNAL(clicked()),this,SLOT(apply())); + connect(resetbut,SIGNAL(clicked()),this,SLOT(reset())); + connect(savebut,SIGNAL(clicked()),this,SLOT(save())); + connect(loadbut,SIGNAL(clicked()),this,SLOT(load())); + connect(closebut,SIGNAL(clicked()),this,SLOT(close())); +} + +SettingDialog::~SettingDialog() +{ +} + +void SettingDialog::save() +{ + apply(); + QDomDocument doc("MeshLabSettings"); + doc.appendChild(tmppar->fillToXMLDocument(doc)); + QString docstring = doc.toString(); + qDebug("Writing into Settings param with name %s and content ****%s****", qUtf8Printable(tmppar->name()), qUtf8Printable(docstring)); + QSettings setting; + setting.setValue(tmppar->name(),QVariant(docstring)); + curPar->value().set(tmppar->value()); +} + +void SettingDialog::apply() +{ + assert(frame.stdfieldwidgets.size() == 1); + frame.stdfieldwidgets.at(0)->collectWidgetValue(); + curPar->value().set(tmppar->value()); + emit applySettingSignal(); +} + +void SettingDialog::reset() +{ + qDebug("resetting the value of param %s to the hardwired default", qUtf8Printable(curPar->name())); + tmppar->value().set(defPar->value()); + assert(frame.stdfieldwidgets.size() == 1); + frame.stdfieldwidgets.at(0)->setWidgetValue(tmppar->value()); + apply(); +} + +void SettingDialog::load() +{ + assert(frame.stdfieldwidgets.size() == 1); + frame.stdfieldwidgets.at(0)->setWidgetValue(curPar->value()); +} + + diff --git a/src/meshlab/customDialog.h b/src/meshlab/meshlab_settings/settingdialog.h similarity index 67% rename from src/meshlab/customDialog.h rename to src/meshlab/meshlab_settings/settingdialog.h index f06efc6ee..8ee253ae6 100644 --- a/src/meshlab/customDialog.h +++ b/src/meshlab/meshlab_settings/settingdialog.h @@ -1,14 +1,14 @@ /**************************************************************************** -* MeshLab o o * -* A versatile mesh processing toolbox o o * +* VCGLib o o * +* Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2005 \/)\/ * +* Copyright(C) 2004-2020 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -21,13 +21,12 @@ * * ****************************************************************************/ +#ifndef SETTINGDIALOG_H +#define SETTINGDIALOG_H #include -#include -#include -#include -#include "meshlab_settings/richparameterlistframe.h" - +#include +#include "richparameterlistframe.h" class SettingDialog : public QDialog { @@ -56,27 +55,4 @@ private: QPushButton* loadbut; }; -class CustomDialog : public QDialog -{ -Q_OBJECT -public: - CustomDialog(RichParameterList& parset,RichParameterList& defparset,QWidget *parent = 0); - ~CustomDialog(); - //void loadCurrentSetting(RichParameterSet& parset); - -public slots: - void openSubDialog(QTableWidgetItem* itm); - void updateSettings(); -signals: - void applyCustomSetting(); - -private: - RichParameterList& curParSet; - RichParameterList& defParSet; - QTableWidget* tw; - QVector vrp; - void dispatch(const RichParameter& par); - QPushButton* closebut; - - static QTableWidgetItem* createQTableWidgetItemFromRichParameter(const RichParameter& pd); -}; +#endif // SETTINGDIALOG_H