KiCad PCB EDA Suite
Loading...
Searching...
No Matches
column_formatter.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "column_formatter.h"
21
22#include <wx/translation.h>
23
24#include <i18n_utility.h>
25
26
27#define BOOL_TRUE _HKI( "True" )
28#define BOOL_FALSE _HKI( "False" )
29
30
31bool MatchTranslationOrNative( const wxString& aStr, const wxString& aNativeLabel, bool aCaseSensitive )
32{
33 return wxGetTranslation( aNativeLabel ).IsSameAs( aStr, aCaseSensitive )
34 || aStr.IsSameAs( aNativeLabel, aCaseSensitive );
35}
36
37
38wxString COLUMN_FORMATTER::stringFromBool( bool aValue ) const
39{
40 switch( m_boolFormat )
41 {
43 return aValue ? wxT( "1" ) : wxT( "0" );
45 return wxGetTranslation( aValue ? BOOL_TRUE : BOOL_FALSE );
46 default:
47 wxFAIL_MSG( "Invalid BOOL_FORMAT" );
48 return wxEmptyString;
49 }
50
51}
52
53
54bool COLUMN_FORMATTER::boolFromString( const wxString& aValue, REPORTER& aReporter ) const
55{
56 if( aValue == wxS( "1" ) )
57 return true;
58 else if( aValue == wxS( "0" ) )
59 return false;
60 else if( MatchTranslationOrNative( aValue, BOOL_TRUE, false ) )
61 return true;
62 else if( MatchTranslationOrNative( aValue, BOOL_FALSE, false ) )
63 return false;
64
65 aReporter.Report( wxString::Format( _( "The value '%s' can't be converted to boolean correctly, "
66 "it has been interpreted as 'False'" ),
67 aValue ),
69 return false;
70}
BOOL_FORMAT m_boolFormat
wxString stringFromBool(bool aValue) const
bool boolFromString(const wxString &aValue, REPORTER &aReporter) const
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
#define BOOL_TRUE
bool MatchTranslationOrNative(const wxString &aStr, const wxString &aNativeLabel, bool aCaseSensitive)
Return true if the given string matches either the translated or native version of the given label.
#define BOOL_FALSE
bool MatchTranslationOrNative(const wxString &aStr, const wxString &aNativeLabel, bool aCaseSensitive)
Return true if the given string matches either the translated or native version of the given label.
#define _(s)
Some functions to handle hotkeys in KiCad.
@ RPT_SEVERITY_ERROR