Salome HOME
Copyright update 2022
[modules/gui.git] / tools / PyEditor / src / PyEditor_StdSettings.cxx
1 // Copyright (C) 2015-2022  OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : PyEditor_StdSettings.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21 //
22
23 #include "PyEditor_StdSettings.h"
24
25 PyEditor_StdSettings::PyEditor_StdSettings() :
26   myLanguage( "en" )
27 {
28   load();
29 }
30
31 PyEditor_StdSettings::PyEditor_StdSettings( const QString& group ) :
32   myGroup( group ),
33   myLanguage( "en" )
34 {
35   load();
36 }
37
38 PyEditor_StdSettings::PyEditor_StdSettings( const QString& group,
39                                             const QString& filename,
40                                             QSettings::Format format ) :
41   mySettings( filename, format ),
42   myGroup( group ),
43   myLanguage( "en" )
44 {
45   load();
46 }
47
48 void PyEditor_StdSettings::setLanguage( const QString& language )
49 {
50   myLanguage = language;
51 }
52
53 QString PyEditor_StdSettings::language() const
54 {
55   return myLanguage;
56 }
57
58 void PyEditor_StdSettings::load()
59 {
60   mySettings.beginGroup( myGroup.isEmpty() ? option( snEditor ) : myGroup );
61
62   setHighlightCurrentLine( mySettings.value( option( snHighlightCurrentLine ),
63                                              highlightCurrentLine() ).toBool() );
64   setTextWrapping( mySettings.value( option( snTextWrapping ),
65                                      textWrapping() ).toBool() );
66   setCenterCursorOnScroll( mySettings.value( option( snCenterCursorOnScroll ),
67                                              centerCursorOnScroll() ).toBool() );
68   setLineNumberArea( mySettings.value( option( snLineNumberArea ),
69                                        lineNumberArea() ).toBool() );
70   setVerticalEdge( mySettings.value( option( snVerticalEdge  ),
71                                      verticalEdge() ).toBool() );
72   setNumberColumns( mySettings.value( option( snNumberColumns ),
73                                       numberColumns() ).toInt() );
74   setTabSpaceVisible( mySettings.value( option( snTabSpaceVisible ),
75                                         tabSpaceVisible() ).toBool() );
76   setTabSize( mySettings.value( option( snTabSize ), tabSize() ).toInt() );
77   setFont( mySettings.value( option( snFont ), font() ).value<QFont>() );
78   setCompletionPolicy( mySettings.value( option( snCompletionPolicy ),
79                                          completionPolicy() ).toInt() );
80   setLanguage( mySettings.value( "language", language() ).toString() );
81
82   mySettings.endGroup();
83 }
84
85 void PyEditor_StdSettings::save()
86 {
87   mySettings.beginGroup( myGroup.isEmpty() ? option( snEditor ) : myGroup );
88
89   mySettings.setValue( option( snHighlightCurrentLine ), highlightCurrentLine() );
90   mySettings.setValue( option( snTextWrapping ), textWrapping() );
91   mySettings.setValue( option( snCenterCursorOnScroll ), centerCursorOnScroll() );
92   mySettings.setValue( option( snLineNumberArea ), lineNumberArea() );
93   mySettings.setValue( option( snVerticalEdge  ), verticalEdge() );
94   mySettings.setValue( option( snNumberColumns ), numberColumns() );
95   mySettings.setValue( option( snTabSpaceVisible ), tabSpaceVisible() );
96   mySettings.setValue( option( snTabSize ), tabSize() );
97   mySettings.setValue( option( snFont ), font() );
98   mySettings.setValue( option( snCompletionPolicy ), completionPolicy() );
99   mySettings.setValue( "language", language() );
100
101   mySettings.endGroup();
102 }