2016-10-24 13:21:49 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2016 Statoil ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2016-10-24 13:21:49 +02: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 10:40:57 +02:00
|
|
|
//
|
2016-10-24 13:21:49 +02: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 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-10-24 13:21:49 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RicEditPreferencesFeature.h"
|
|
|
|
|
|
2019-05-06 10:36:05 +02:00
|
|
|
#include "RiaGuiApplication.h"
|
2023-02-20 08:18:08 +01:00
|
|
|
#include "RiaNetworkTools.h"
|
2016-10-24 13:21:49 +02:00
|
|
|
#include "RiaPreferences.h"
|
2023-02-20 08:18:08 +01:00
|
|
|
|
2020-05-09 11:23:58 +02:00
|
|
|
#include "RimProject.h"
|
2016-10-24 13:21:49 +02:00
|
|
|
|
|
|
|
|
#include "RiuPropertyViewTabWidget.h"
|
|
|
|
|
|
|
|
|
|
#include "cafPdmSettings.h"
|
2019-08-07 14:21:37 +02:00
|
|
|
#include "cafPdmUiModelChangeDetector.h"
|
2016-10-24 13:21:49 +02:00
|
|
|
|
|
|
|
|
#include <QAction>
|
2023-02-20 08:18:08 +01:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QPushButton>
|
2016-10-24 13:21:49 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_CMD_SOURCE_INIT( RicEditPreferencesFeature, "RicEditPreferencesFeature" );
|
2016-10-24 13:21:49 +02:00
|
|
|
|
2020-05-09 11:23:58 +02:00
|
|
|
std::vector<caf::FontHolderInterface*> findFontObjects()
|
|
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
auto project = RimProject::current();
|
|
|
|
|
std::vector<caf::FontHolderInterface*> allFontObjects = project->descendantsIncludingThisOfType<caf::FontHolderInterface>();
|
2020-05-09 11:23:58 +02:00
|
|
|
|
|
|
|
|
std::vector<caf::FontHolderInterface*> defaultFontObjects;
|
|
|
|
|
for ( auto fontObject : allFontObjects )
|
|
|
|
|
{
|
|
|
|
|
defaultFontObjects.push_back( fontObject );
|
2020-06-08 09:09:11 +00:00
|
|
|
}
|
2020-05-09 11:23:58 +02:00
|
|
|
return defaultFontObjects;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 13:21:49 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2016-10-24 13:21:49 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicEditPreferencesFeature::onActionTriggered( bool isChecked )
|
2016-10-24 13:21:49 +02:00
|
|
|
{
|
2023-08-04 09:04:14 +02:00
|
|
|
disableModelChangeContribution();
|
2017-04-20 10:38:58 +02:00
|
|
|
|
2019-05-06 10:36:05 +02:00
|
|
|
RiaGuiApplication* app = RiaGuiApplication::instance();
|
2016-10-24 13:21:49 +02:00
|
|
|
|
|
|
|
|
QStringList tabNames = app->preferences()->tabNames();
|
2019-04-02 13:28:31 +02:00
|
|
|
|
2020-05-09 11:23:58 +02:00
|
|
|
auto defaultFontObjects = findFontObjects();
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
std::unique_ptr<RiaPreferences> oldPreferences = clonePreferences( app->preferences() );
|
2019-04-02 13:28:31 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
RiuPropertyViewTabWidget propertyDialog( nullptr, app->preferences(), "Preferences", tabNames );
|
2023-02-20 08:18:08 +01:00
|
|
|
|
|
|
|
|
auto pushButton = propertyDialog.dialogButtonBox()->addButton( "Help", QDialogButtonBox::HelpRole );
|
|
|
|
|
connect( pushButton, &QPushButton::clicked, this, &RicEditPreferencesFeature::showHelp );
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( propertyDialog.exec() == QDialog::Accepted )
|
2016-10-24 13:21:49 +02:00
|
|
|
{
|
|
|
|
|
// Write preferences using QSettings and apply them to the application
|
2019-09-05 19:37:52 +02:00
|
|
|
app->applyPreferences();
|
2020-05-09 11:23:58 +02:00
|
|
|
app->applyGuiPreferences( oldPreferences.get(), defaultFontObjects );
|
2016-10-24 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Read back currently stored values using QSettings
|
2019-09-06 10:40:57 +02:00
|
|
|
caf::PdmSettings::readFieldsFromApplicationStore( app->preferences() );
|
2019-05-13 13:47:03 +02:00
|
|
|
app->preferences()->initAfterReadRecursively();
|
2016-10-24 13:21:49 +02:00
|
|
|
}
|
2019-08-07 14:21:37 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( !app->isProjectSavedToDisc() )
|
2019-08-07 14:21:37 +02: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 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2016-10-24 13:21:49 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicEditPreferencesFeature::setupActionLook( QAction* actionToSetup )
|
2016-10-24 13:21:49 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
actionToSetup->setText( "&Preferences..." );
|
2016-10-24 13:21:49 +02:00
|
|
|
}
|
2019-04-02 13:28:31 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
std::unique_ptr<RiaPreferences> RicEditPreferencesFeature::clonePreferences( const RiaPreferences* preferences )
|
2019-04-02 13:28:31 +02:00
|
|
|
{
|
2024-06-14 17:18:28 +02:00
|
|
|
return std::unique_ptr<RiaPreferences>( preferences->copyObject<RiaPreferences>() );
|
2019-04-02 13:28:31 +02:00
|
|
|
}
|
2023-02-20 08:18:08 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RicEditPreferencesFeature::showHelp()
|
|
|
|
|
{
|
|
|
|
|
RiaNetworkTools::openSearchPage( "preferences" );
|
|
|
|
|
}
|