20#include "KPrVariableCollection.h"
21#include <KoVariable.h>
22#include "KPrDocument.h"
23#include "KPrCommand.h"
28#include "KPrTextObject.h"
31KPrVariableCollection::KPrVariableCollection(KoVariableSettings *_setting, KoVariableFormatCollection* coll)
32 : KoVariableCollection(_setting, coll)
36KoVariable* KPrVariableCollection::loadOasisField( KoTextDocument* textdoc,
const TQDomElement& tag, KoOasisContext& context )
38 const TQString localName( tag.localName() );
39 const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
42 if ( localName ==
"object-count" ||
43 localName ==
"picture-count" ||
44 localName ==
"paragraph-count" ||
45 localName ==
"word-count" ||
46 localName ==
"character-count" ||
47 localName ==
"sentence-count" ||
48 localName ==
"line-count" ||
49 localName ==
"frame-count" ||
50 localName ==
"non-whitespace-character-count" ||
51 localName ==
"syllable-count" )
53 TQString key =
"NUMBER";
54 int type = VT_STATISTIC;
55 return loadOasisFieldCreateVariable( textdoc, tag, context, key, type );
58 return KoVariableCollection::loadOasisField( textdoc, tag, context );
61 return KoVariableCollection::loadOasisField( textdoc, tag, context );
64KoVariable *KPrVariableCollection::createVariable(
int type,
short int subtype, KoVariableFormatCollection * coll,
65 KoVariableFormat *varFormat,KoTextDocument *textdoc,
66 KoDocument * doc,
int _correct,
bool _forceDefaultFormat,
bool )
68 KPrDocument*m_doc=
static_cast<KPrDocument*
>(doc);
69 KoVariable * var = 0L;
73 kdDebug(33001)<<
" subtype == KoPageVariable::VST_CURRENT_SECTION :"<<(subtype == KPrPgNumVariable::VST_CURRENT_SECTION)<<endl;
74 kdDebug(33001)<<
" varFormat :"<<varFormat<<endl;
76 varFormat = (subtype == KPrPgNumVariable::VST_CURRENT_SECTION) ? coll->format(
"STRING") : coll->format(
"NUMBER");
82 varFormat = coll->format(
"NUMBER");
83 var =
new KPrStatisticVariable( textdoc, subtype, varFormat,
this, m_doc );
86 return KoVariableCollection::createVariable( type, subtype, coll, varFormat, textdoc,
87 doc, _correct, _forceDefaultFormat);
93KPrPgNumVariable::KPrPgNumVariable( KoTextDocument *textdoc,
short int subtype, KoVariableFormat *varFormat,
94 KoVariableCollection *_varColl, KPrDocument *doc )
95 : KoPageVariable( textdoc, subtype, varFormat ,_varColl ),m_doc(doc)
99void KPrPgNumVariable::recalc()
101 if ( m_subtype == VST_PGNUM_TOTAL )
103 m_varValue = TQVariant( (
int)(m_doc->getPageNums()+m_varColl->variableSetting()->startingPageNumber()-1));
111KPrStatisticVariable::KPrStatisticVariable( KoTextDocument *textdoc,
int subtype, KoVariableFormat *varFormat,KoVariableCollection *_varColl, KPrDocument *doc )
112 : KoStatisticVariable( textdoc, subtype, varFormat, _varColl ),
117void KPrStatisticVariable::recalc()
120 ulong charsWithSpace = 0L;
121 ulong charsWithoutSpace = 0L;
123 ulong sentences = 0L;
125 ulong syllables = 0L;
126 bool frameInfo = ( m_subtype == VST_STATISTIC_NB_WORD ||
127 m_subtype == VST_STATISTIC_NB_SENTENCE ||
128 m_subtype == VST_STATISTIC_NB_LINES ||
129 m_subtype == VST_STATISTIC_NB_CHARACTERE);
130 KPrPage *page = m_doc->activePage();
133 TQPtrListIterator<KPrObject> objIt( page->objectList() );
135 for ( objIt.toFirst(); objIt.current(); ++objIt )
137 KPrObject *obj = objIt.current();
138 if ( m_subtype == VST_STATISTIC_NB_FRAME )
140 else if( m_subtype == VST_STATISTIC_NB_PICTURE && obj->getType() == OT_PICTURE)
144 else if( m_subtype == VST_STATISTIC_NB_EMBEDDED && obj->getType() == OT_PART )
150 KPrTextObject *textObj =
dynamic_cast<KPrTextObject *
>( obj );
152 textObj->textObject()->statistics( 0L, charsWithSpace, charsWithoutSpace, words, sentences, syllables, lines,
false );
157 if( m_subtype == VST_STATISTIC_NB_WORD )
161 else if( m_subtype == VST_STATISTIC_NB_SENTENCE )
165 else if( m_subtype == VST_STATISTIC_NB_LINES )
169 else if ( m_subtype == VST_STATISTIC_NB_CHARACTERE )
173 else if ( m_subtype ==VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE )
175 nb = charsWithoutSpace;
177 else if ( m_subtype ==VST_STATISTIC_NB_SYLLABLE )
185 m_varValue = TQVariant(nb);
191TQString KPrStatisticVariable::text(
bool realValue)
193 if (m_varColl->variableSetting()->displayFieldCode()&& !realValue)
196 return m_varFormat->convert( m_varValue );
"current page number" and "number of pages" variables