From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kexi/plugins/macros/lib/macroitem.cpp | 217 ++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 kexi/plugins/macros/lib/macroitem.cpp (limited to 'kexi/plugins/macros/lib/macroitem.cpp') diff --git a/kexi/plugins/macros/lib/macroitem.cpp b/kexi/plugins/macros/lib/macroitem.cpp new file mode 100644 index 000000000..4027f2ccc --- /dev/null +++ b/kexi/plugins/macros/lib/macroitem.cpp @@ -0,0 +1,217 @@ +/*************************************************************************** + * This file is part of the KDE project + * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org) + * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ***************************************************************************/ + +#include "macroitem.h" + +#include + +using namespace KoMacro; + +namespace KoMacro { + + /** + * @internal d-pointer class to be more flexible on future extension of the + * functionality without to much risk to break the binary compatibility. + */ + class MacroItem::Private + { + public: + /** + * The @a Action this @a MacroItem has. + */ + KSharedPtr action; + + /** + * The comment this @a MacroItem has. + */ + QString comment; + + /** + * The @a QMap of @a Variable this @a MacroItem has. + */ + Variable::Map variables; + + /** + * define a @a QVariant -cast as inline for better performance + * @return the casted @a QVariant by passing a @param variant and its + * expected QVariant::Type @param type. + */ + inline const QVariant cast(const QVariant& variant, QVariant::Type type) const + { + // If ok is true the QVariant v holds our new and to the correct type + // casted variant value. If ok is false the as argument passed variant + // QVariant contains the (maybe uncasted string to prevent data-loosing + // what would happen if we e.g. would expect an integer and cast it to + // an incompatible non-int string) value. + bool ok = false; + QVariant v; + + // Try to cast the passed variant to the expected variant-type. + switch(type) { + case QVariant::Bool: { + const QString s = variant.toString(); + ok = (s == "true" || s == "false" || s == "0" || s == "1" || s == "-1"); + v = QVariant( variant.toBool(), 0 ); + } break; + case QVariant::Int: { + v = variant.toInt(&ok); + // Check if the cast is correct. + Q_ASSERT(!ok || v.toString() == variant.toString()); + } break; + case QVariant::UInt: { + v = variant.toUInt(&ok); + Q_ASSERT(!ok || v.toString() == variant.toString()); + } break; + case QVariant::LongLong: { + v = variant.toLongLong(&ok); + Q_ASSERT(!ok || v.toString() == variant.toString()); + } break; + case QVariant::ULongLong: { + v = variant.toULongLong(&ok); + Q_ASSERT(!ok || v.toString() == variant.toString()); + } break; + case QVariant::Double: { + v = variant.toDouble(&ok); + Q_ASSERT(!ok || v.toString() == variant.toString()); + } break; + case QVariant::String: { + ok = true; // cast will always be successfully + v = variant.toString(); + } break; + default: { + // If we got another type we try to let Qt handle it... + ok = v.cast(type); + kdWarning()<<"MacroItem::Private::cast() Unhandled ok="<