1 /***************************************************************************
2     Copyright (C) 2001-2009 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #ifndef TELLICO_DATA_DERIVEDVALUE_H
26 #define TELLICO_DATA_DERIVEDVALUE_H
27 
28 #include "datavectors.h"
29 #include "entry.h"
30 
31 #include <QRegExp>
32 
33 namespace Tellico {
34   namespace Data {
35 
36 class DerivedValue {
37 public:
38   DerivedValue(const QString& valueTemplate);
39   DerivedValue(FieldPtr field);
40 
41   // the reason we don't use a CollPtr is because this gets
42   // called when adding fields in the Collection() constructor
43   // which would create a ptr then destroy it and dereference the object
44   bool isRecursive(Collection* coll) const;
45 
46   QString value(EntryPtr entry, bool formatted) const;
47 
48 private:
49   QStringList templateFields() const;
50   QString templateKeyValue(EntryPtr entry, const QString& key, bool formatted) const;
51 
52   QString m_fieldName;
53   QString m_valueTemplate;
54   mutable QRegExp m_keyRx;
55 };
56 
57   } // end namespace
58 } // end namespace
59 
60 #endif
61