Qt Virtual Chart Table (QVCT)
COverlayText.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QLabel>
21 #include <QWidget>
22 
23 // QVCT
25 
26 
27 //------------------------------------------------------------------------------
28 // CONSTRUCTORS / DESTRUCTOR
29 //------------------------------------------------------------------------------
30 
31 COverlayText::COverlayText( QWidget* _pqParent )
32  : QLabel( _pqParent )
33 {}
34 
35 COverlayText::COverlayText( const QString& _rqsText, QWidget* _pqParent )
36  : QLabel( _pqParent )
37 {
38  setText( _rqsText, !_rqsText.length() );
39 }
40 
41 //------------------------------------------------------------------------------
42 // METHODS: QLabel (override)
43 //------------------------------------------------------------------------------
44 
45 void COverlayText::setText( const QString& _rqsText )
46 {
47  setText( _rqsText, !_rqsText.length() );
48 }
49 
50 
51 //------------------------------------------------------------------------------
52 // METHODS
53 //------------------------------------------------------------------------------
54 
55 //
56 // SETTERS
57 //
58 
59 void COverlayText::setText( const QString& _rqsText, bool _bInvalid )
60 {
61  QFont __qFont = QLabel::font();
62  __qFont.setItalic( _bInvalid );
63  QLabel::setFont( __qFont );
64  QLabel::setText( _rqsText.length() ? _rqsText : emptyString() );
65 }
66 
68 {
69  QFont __qFont = QLabel::font();
70  __qFont.setItalic( true );
71  QLabel::setFont( __qFont );
72  QLabel::setText( emptyString() );
73 }
74 
75 //
76 // OTHER
77 //
78 
79 const QString& COverlayText::emptyString()
80 {
81  static const QString __qsEmpty( tr("n/a") );
82  return __qsEmpty;
83 }
84 
85 QString COverlayText::formatString( const QString& _rqsString )
86 {
87  return( _rqsString.length() ? _rqsString : emptyString() );
88 }
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
COverlayText(QWidget *_pqParent=0)
QString formatString(const QString &_rqsString)
Returns the string properly formatted if it is undefined (empty)
const QString & emptyString()
Returns the string corresponding to undefined (empty) content ("n/a" in English)
void resetText()
Resets (clears) the underlying QLabel's text.