Warning, file /office/calligra/libs/text/KoVariableManager.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2008, 2011 Sebastian Sauer <mail@dipe.org> 0004 * Copyright (C) 2011 Robert Mathias Marmorstein <robert@narnia.homeunix.com> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 #ifndef KOVARIABLEMANAGER_H 0022 #define KOVARIABLEMANAGER_H 0023 0024 #include "kotext_export.h" 0025 0026 #include <QObject> 0027 #include <QString> 0028 #include <KoXmlReaderForward.h> 0029 0030 class KoXmlWriter; 0031 class KoVariable; 0032 class KoInlineTextObjectManager; 0033 class KoVariableManagerPrivate; 0034 0035 /** 0036 * A document can maintain a list of name-value pairs, which we call variables. 0037 * These initially exist solely in the variableManager as such name/value pairs 0038 * and can be managed by setValue(), value() and remove(). 0039 * When the user chooses to use one of these pairs in the text-document they can create a 0040 * new KoNamedVariable by calling KoVariableManager::createVariable() 0041 * use that and insert that into the text-document. 0042 * Changing the value will lead to directly change the value of all variables 0043 * inserted into the document. 0044 * @see KoInlineTextObjectManager::createInsertVariableActions() 0045 * @see KoInlineTextObjectManager::variableManager() 0046 */ 0047 class KOTEXT_EXPORT KoVariableManager : public QObject 0048 { 0049 Q_OBJECT 0050 public: 0051 /// constructor 0052 explicit KoVariableManager(KoInlineTextObjectManager *inlineObjectManager); 0053 ~KoVariableManager() override; 0054 0055 /** 0056 * Set or create a variable to the new value. 0057 * @param name the name of the variable. 0058 * @param value the new value. 0059 * @param type The type of the value. This is only set for user-defined variables. 0060 * For non user defined variables the value is empty. If set then it should be one 0061 * of the following values; 0062 * \li string 0063 * \li boolean 0064 * \li currency 0065 * \li date 0066 * \li float 0067 * \li percentage 0068 * \li time 0069 * \li void 0070 * \li formula 0071 */ 0072 void setValue(const QString &name, const QString &value, const QString &type = QString()); 0073 0074 /** 0075 * Remove a variable from the store. 0076 * Variables that were created and inserted into text will no longer get updated, but will keep 0077 * showing the proper text. 0078 * @see usageCount() 0079 */ 0080 void remove(const QString &name); 0081 0082 /** 0083 * Return the value a named variable currently has. Or an empty string if none. 0084 */ 0085 QString value(const QString &name) const; 0086 0087 /** 0088 * Return the type of a user defined variable. If the variable does not exist or 0089 * is not a user defined variable then an empty string is returned. 0090 */ 0091 QString userType(const QString &name) const; 0092 0093 /** 0094 * Create a new variable that can be inserted into the document using 0095 * KoInlineTextObjectManager::insertInlineObject() 0096 * This is a factory method that creates a visible variable object of an already existing 0097 * name/value pair previously inserted into the manager. 0098 * @param name the named variable. 0099 * @return the new variable, or 0 when the name was not previously set on this manager 0100 * @see setValue() 0101 */ 0102 KoVariable *createVariable(const QString &name) const; 0103 0104 /// return a list of all variable names. 0105 QList<QString> variables() const; 0106 /// return a list of all user defined variable names. 0107 QList<QString> userVariables() const; 0108 0109 /** 0110 * Load user defined variable declarations from the ODF body-element. 0111 */ 0112 void loadOdf(const KoXmlElement &bodyElement); 0113 0114 /** 0115 * Save user defined variable declarations into the ODF writer. 0116 */ 0117 void saveOdf(KoXmlWriter *bodyWriter); 0118 0119 Q_SIGNALS: 0120 void valueChanged(); 0121 0122 private: 0123 KoVariableManagerPrivate * const d; 0124 }; 0125 0126 #endif