mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4949 Summary Curve Filter Toolbar : Store recently used strings to registry
This commit is contained in:
@@ -17,6 +17,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -38,6 +39,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaFeatureCommandContext.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
69
ApplicationCode/Application/RiaStringListSerializer.cpp
Normal file
69
ApplicationCode/Application/RiaStringListSerializer.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Equinor ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaStringListSerializer.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaStringListSerializer::RiaStringListSerializer( const QString& key )
|
||||
: m_key( key )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaStringListSerializer::addString( const QString& textString, int maxStringCount )
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList stringList = settings.value( m_key ).toStringList();
|
||||
|
||||
stringList.removeAll( textString );
|
||||
stringList.prepend( textString );
|
||||
while ( stringList.size() > maxStringCount )
|
||||
stringList.removeLast();
|
||||
|
||||
settings.setValue( m_key, stringList );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaStringListSerializer::removeString( const QString& textString )
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList files = settings.value( m_key ).toStringList();
|
||||
files.removeAll( textString );
|
||||
|
||||
settings.setValue( m_key, files );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaStringListSerializer::textStrings()
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList stringList = settings.value( m_key ).toStringList();
|
||||
|
||||
return stringList;
|
||||
}
|
||||
40
ApplicationCode/Application/RiaStringListSerializer.h
Normal file
40
ApplicationCode/Application/RiaStringListSerializer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- Equinor ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
class QStringList;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaStringListSerializer
|
||||
{
|
||||
public:
|
||||
RiaStringListSerializer( const QString& key );
|
||||
|
||||
void addString( const QString& textString, int maxStringCount );
|
||||
void removeString( const QString& textString );
|
||||
|
||||
QStringList textStrings();
|
||||
|
||||
private:
|
||||
QString m_key;
|
||||
};
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStringListSerializer.h"
|
||||
#include "RiaSummaryCurveDefinition.h"
|
||||
|
||||
#include "RifSummaryReaderInterface.h"
|
||||
@@ -384,14 +385,10 @@ void RimSummaryPlotFilterTextCurveSetEditor::fieldChangedByUi( const caf::PdmFie
|
||||
m_curveFilterText = curveFilterTextWithoutOutdatedLabel();
|
||||
|
||||
{
|
||||
if ( m_historyItems.indexOf( m_curveFilterText ) == -1 )
|
||||
{
|
||||
m_historyItems.push_front( m_curveFilterText );
|
||||
while ( m_historyItems.size() > 10 )
|
||||
{
|
||||
m_historyItems.pop_back();
|
||||
}
|
||||
}
|
||||
RiaStringListSerializer stringListSerializer( curveFilterRecentlyUsedRegistryKey() );
|
||||
|
||||
int maxItemCount = 10;
|
||||
stringListSerializer.addString( m_curveFilterText, maxItemCount );
|
||||
}
|
||||
|
||||
m_curveFilterText.uiCapability()->updateConnectedEditors();
|
||||
@@ -485,7 +482,9 @@ QList<caf::PdmOptionItemInfo>
|
||||
|
||||
if ( fieldNeedingOptions == &m_curveFilterText )
|
||||
{
|
||||
for ( const auto& s : m_historyItems )
|
||||
RiaStringListSerializer stringListSerializer( curveFilterRecentlyUsedRegistryKey() );
|
||||
|
||||
for ( const auto& s : stringListSerializer.textStrings() )
|
||||
{
|
||||
options.push_back( caf::PdmOptionItemInfo( s, s ) );
|
||||
}
|
||||
@@ -607,3 +606,11 @@ QString RimSummaryPlotFilterTextCurveSetEditor::curveFilterTextWithoutOutdatedLa
|
||||
|
||||
return filterText;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimSummaryPlotFilterTextCurveSetEditor::curveFilterRecentlyUsedRegistryKey()
|
||||
{
|
||||
return "curveFilterRecentlyUsedStrings";
|
||||
}
|
||||
|
||||
@@ -57,11 +57,13 @@ private:
|
||||
std::vector<SummarySource*> selectedSummarySources() const;
|
||||
QString curveFilterTextWithoutOutdatedLabel() const;
|
||||
|
||||
static QString curveFilterRecentlyUsedRegistryKey();
|
||||
|
||||
private:
|
||||
caf::PdmPtrArrayField<SummarySource*> m_selectedSources;
|
||||
|
||||
caf::PdmField<QString> m_curveFilterLabelText;
|
||||
caf::PdmField<QString> m_curveFilterText;
|
||||
QStringList m_historyItems;
|
||||
|
||||
bool m_isFieldRecentlyChangedFromGui;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user