Testing tool for encoding string lists for ZionWorx bible passages
[kworship.git] / kworship / css / KwCssStyleState.h
blobe65109181fd44f4a17b454b8173c5b47fd4fb49b
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship 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 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship 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 received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #ifndef _KwCssStyleState_h_
21 #define _KwCssStyleState_h_
23 /**
24 * @file KwCssStyleState.h
25 * @brief Typed cascading style property state.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssAbstractStyleState.h"
30 #include "KwCssStyle.h"
32 #include <QStack>
34 #include <cassert>
36 /// Typed cascading style property state.
37 /**
38 * @param T The type of the property.
40 template <typename T>
41 class KwCssStyleState : public KwCssAbstractStyleState
43 public:
46 * Constructors + destructors
49 /// Default constructor.
50 KwCssStyleState()
51 : KwCssAbstractStyleState()
52 , m_value()
56 /// Copy constructor.
57 KwCssStyleState(const KwCssStyleState& copy)
58 : KwCssAbstractStyleState(copy)
59 , m_value(copy.m_value)
63 /// Destructor.
64 virtual ~KwCssStyleState()
69 * Main interface
72 /// Create a new style for this state.
73 virtual KwCssAbstractStyle* createStyle() const
75 return new KwCssStyle<T>;
78 /// Duplicate this style.
79 virtual KwCssAbstractStyleState* duplicate() const
81 return new KwCssStyleState<T>(*this);
84 T getValue() const
86 if (!m_value.empty())
88 return m_value.back();
90 else
92 return T();
97 * Operators
100 /// Apply the style to this state.
101 virtual KwCssAbstractStyleState& operator << (const KwCssAbstractStyle* style)
103 const KwCssStyle<T>* styleRetyped = dynamic_cast<const KwCssStyle<T>*>(style);
104 assert(styleRetyped != 0 &&"Bad style type for this style state");
106 switch (styleRetyped->getOperation())
108 case KwCssStyle<T>::override:
110 m_value.push_back(styleRetyped->getValue());
111 break;
113 case KwCssStyle<T>::revert:
115 if (m_value.size() != 0)
117 m_value.pop_back();
119 break;
121 case KwCssStyle<T>::clear:
123 m_value.clear();
124 break;
126 default:
128 // No change
129 break;
132 return *this;
135 private:
138 * Variables
141 /// Stack of values.
142 QStack<T> m_value;
145 #endif // _KwCssStyleState_h_