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"
|
2023-02-20 01:18:08 -06:00
|
|
|
#include "RiaNetworkTools.h"
|
2016-10-24 06:21:49 -05:00
|
|
|
#include "RiaPreferences.h"
|
2023-02-20 01:18:08 -06:00
|
|
|
|
2020-05-09 04:23:58 -05:00
|
|
|
#include "RimProject.h"
|
2016-10-24 06:21:49 -05:00
|
|
|
|
|
|
|
#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>
|
2023-02-20 01:18:08 -06:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QPushButton>
|
2016-10-24 06:21:49 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_CMD_SOURCE_INIT( RicEditPreferencesFeature, "RicEditPreferencesFeature" );
|
2016-10-24 06:21:49 -05:00
|
|
|
|
2020-05-09 04:23:58 -05:00
|
|
|
std::vector<caf::FontHolderInterface*> findFontObjects()
|
|
|
|
{
|
2023-05-12 14:41:34 -05:00
|
|
|
auto project = RimProject::current();
|
|
|
|
std::vector<caf::FontHolderInterface*> allFontObjects = project->descendantsIncludingThisOfType<caf::FontHolderInterface>();
|
2020-05-09 04:23:58 -05:00
|
|
|
|
|
|
|
std::vector<caf::FontHolderInterface*> defaultFontObjects;
|
|
|
|
for ( auto fontObject : allFontObjects )
|
|
|
|
{
|
|
|
|
defaultFontObjects.push_back( fontObject );
|
2020-06-08 04:09:11 -05:00
|
|
|
}
|
2020-05-09 04:23:58 -05:00
|
|
|
return defaultFontObjects;
|
|
|
|
}
|
|
|
|
|
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::onActionTriggered( bool isChecked )
|
2016-10-24 06:21:49 -05:00
|
|
|
{
|
2023-08-04 02:04:14 -05:00
|
|
|
disableModelChangeContribution();
|
2017-04-20 03:38:58 -05:00
|
|
|
|
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
|
|
|
|
2020-05-09 04:23:58 -05:00
|
|
|
auto defaultFontObjects = findFontObjects();
|
|
|
|
|
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 );
|
2023-02-20 01:18:08 -06:00
|
|
|
|
|
|
|
auto pushButton = propertyDialog.dialogButtonBox()->addButton( "Help", QDialogButtonBox::HelpRole );
|
|
|
|
connect( pushButton, &QPushButton::clicked, this, &RicEditPreferencesFeature::showHelp );
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
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();
|
2020-05-09 04:23:58 -05:00
|
|
|
app->applyGuiPreferences( oldPreferences.get(), defaultFontObjects );
|
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
|
|
|
{
|
2024-06-14 10:18:28 -05:00
|
|
|
return std::unique_ptr<RiaPreferences>( preferences->copyObject<RiaPreferences>() );
|
2019-04-02 06:28:31 -05:00
|
|
|
}
|
2023-02-20 01:18:08 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicEditPreferencesFeature::showHelp()
|
|
|
|
{
|
|
|
|
RiaNetworkTools::openSearchPage( "preferences" );
|
|
|
|
}
|