GobChartsWidget  1.0
gobchartsvaliditems.cpp
1 /* Copyright (C) 2012 by William Hallatt.
2  *
3  * This file forms part of the "GobChartsWidget" library.
4  *
5  * This library is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have downloaded a copy of the GNU General Public License
16  * (GNUGPL.txt) and GNU Lesser General Public License (GNULGPL.txt)
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * The official website for this project is www.goblincoding.com and,
20  * although not compulsory, it would be appreciated if all works of whatever
21  * nature referring to or using this library include a reference to this site.
22  */
23 
24 #include "gobchartsvaliditems.h"
25 
27  QObject ( parent ),
28  m_validMap()
29 {
30 }
31 
32 /*--------------------------------------------------------------------------------*/
33 
35 {
36  // Default destructor
37 }
38 
39 /*--------------------------------------------------------------------------------*/
40 
41 void GobChartsValidItems::addValidItem( int row, QString category, qreal data )
42 {
43  ItemPair pair;
44  pair.first = category;
45  pair.second = data;
46  m_validMap.insert( row, pair );
47 }
48 
49 /*--------------------------------------------------------------------------------*/
50 
52 {
53  m_validMap.clear();
54 }
55 
56 /*--------------------------------------------------------------------------------*/
57 
58 const QList< int > GobChartsValidItems::validRows() const
59 {
60  return m_validMap.keys();
61 }
62 
63 /*--------------------------------------------------------------------------------*/
64 
65 QString GobChartsValidItems::category( int row) const
66 {
67  if( m_validMap.find( row ) != m_validMap.end() )
68  {
69  return m_validMap.value( row ).first.trimmed();
70  }
71 
72  return QString( "Invalid Row" );
73 }
74 
75 /*--------------------------------------------------------------------------------*/
76 
77 qreal GobChartsValidItems::data( int row ) const
78 {
79  if( m_validMap.find( row ) != m_validMap.end() )
80  {
81  return m_validMap.value( row ).second;
82  }
83 
84  return 0.0;
85 }
86 
87 /*--------------------------------------------------------------------------------*/
88 
90 {
91  return m_validMap.size();
92 }
93 
94 /*--------------------------------------------------------------------------------*/