2016-10-24 06:21:49 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-10-24 06:21:49 -05:00
|
|
|
// ResInsight 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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-10-24 06:21:49 -05:00
|
|
|
// ResInsight 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-10-24 06:21:49 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicEditPreferencesFeature.h"
|
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
2016-10-24 06:21:49 -05:00
|
|
|
#include "RiaPreferences.h"
|
|
|
|
|
|
|
|
#include "RiuPropertyViewTabWidget.h"
|
|
|
|
|
|
|
|
#include "cafPdmSettings.h"
|
2019-08-07 07:21:37 -05:00
|
|
|
#include "cafPdmUiModelChangeDetector.h"
|
2016-10-24 06:21:49 -05:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicEditPreferencesFeature, "RicEditPreferencesFeature" );
|
2016-10-24 06:21:49 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-10-24 06:21:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicEditPreferencesFeature::isCommandEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-10-24 06:21:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicEditPreferencesFeature::onActionTriggered( bool isChecked )
|
2016-10-24 06:21:49 -05:00
|
|
|
{
|
2017-04-20 03:38:58 -05:00
|
|
|
this->disableModelChangeContribution();
|
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
RiaGuiApplication* app = RiaGuiApplication::instance();
|
2016-10-24 06:21:49 -05:00
|
|
|
|
|
|
|
QStringList tabNames = app->preferences()->tabNames();
|
2019-04-02 06:28:31 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::unique_ptr<RiaPreferences> oldPreferences = clonePreferences( app->preferences() );
|
2019-04-02 06:28:31 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuPropertyViewTabWidget propertyDialog( nullptr, app->preferences(), "Preferences", tabNames );
|
|
|
|
propertyDialog.setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|
|
|
if ( propertyDialog.exec() == QDialog::Accepted )
|
2016-10-24 06:21:49 -05:00
|
|
|
{
|
|
|
|
// Write preferences using QSettings and apply them to the application
|
2019-09-05 12:37:52 -05:00
|
|
|
app->applyPreferences();
|
2019-09-06 05:53:32 -05:00
|
|
|
app->applyGuiPreferences( oldPreferences.get() );
|
2019-05-20 06:21:02 -05:00
|
|
|
app->updateGrpcServer();
|
2016-10-24 06:21:49 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Read back currently stored values using QSettings
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmSettings::readFieldsFromApplicationStore( app->preferences() );
|
2019-05-13 06:47:03 -05:00
|
|
|
app->preferences()->initAfterReadRecursively();
|
2016-10-24 06:21:49 -05:00
|
|
|
}
|
2019-08-07 07:21:37 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !app->isProjectSavedToDisc() )
|
2019-08-07 07:21:37 -05:00
|
|
|
{
|
|
|
|
// Always reset change detector when modifying preferences, as these changes are irrelevant
|
|
|
|
// when the project we work on is not saved to disc
|
|
|
|
caf::PdmUiModelChangeDetector::instance()->reset();
|
|
|
|
}
|
2016-10-24 06:21:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-10-24 06:21:49 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicEditPreferencesFeature::setupActionLook( QAction* actionToSetup )
|
2016-10-24 06:21:49 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
actionToSetup->setText( "&Preferences..." );
|
2016-10-24 06:21:49 -05:00
|
|
|
}
|
2019-04-02 06:28:31 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
std::unique_ptr<RiaPreferences> RicEditPreferencesFeature::clonePreferences( const RiaPreferences* preferences )
|
2019-04-02 06:28:31 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmObjectHandle* pdmClone = preferences->xmlCapability()->copyByXmlSerialization(
|
|
|
|
caf::PdmDefaultObjectFactory::instance() );
|
|
|
|
|
|
|
|
return std::unique_ptr<RiaPreferences>( dynamic_cast<RiaPreferences*>( pdmClone ) );
|
2019-04-02 06:28:31 -05:00
|
|
|
}
|