• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • datatypes
  • primitive
uintdatainformation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #include "uintdatainformation.h"
23 #include <QScriptValue>
24 
25 #include <KGlobal>
26 #include <KLocale>
27 #include <KDebug>
28 
29 #include "../../../poddecoder/typeeditors/uintspinbox.h"
30 #include "structviewpreferences.h"
31 
32 
33 template<typename T>
34 QScriptValue UIntDataInformationMethods<T>::asScriptValue(T value, QScriptEngine* engine, ScriptHandlerInfo* handlerInfo)
35 {
36  Q_UNUSED(engine);
37  Q_UNUSED(handlerInfo);
38  return QScriptValue(value);
39 }
40 
41 template<>
42 QScriptValue UIntDataInformationMethods<quint64>::asScriptValue(quint64 value, QScriptEngine* engine,
43  ScriptHandlerInfo* handlerInfo)
44 {
45  Q_UNUSED(engine);
46  Q_UNUSED(handlerInfo);
47  return QScriptValue(QString::number(value, 10));
48 }
49 
50 template<typename T>
51 QString UIntDataInformationMethods<T>::staticValueString(T value, int base)
52 {
53  QString num = QString::number(value, base);
54  if (base == 10)
55  {
56  if (Kasten2::StructViewPreferences::localeAwareDecimalFormatting())
57  num = KGlobal::locale()->formatNumber(num, false, 0);
58  }
59  else
60  {
61  //add one space every 8 chars
62  for (int i = 8; i < num.length(); i += 9)
63  {
64  num.insert(num.length() - i, QLatin1Char(' '));
65  }
66  }
67  return PrimitiveDataInformation::basePrefix(base) + num;
68 }
69 
70 template<typename T>
71 inline QWidget* UIntDataInformationMethods<T>::staticCreateEditWidget(QWidget* parent)
72 {
73  UIntSpinBox* ret = new UIntSpinBox(parent, Kasten2::StructViewPreferences::unsignedDisplayBase());
74  ret->setMaximum(std::numeric_limits<T>::max());
75  return ret;
76 }
77 
78 template<typename T>
79 inline QVariant UIntDataInformationMethods<T>::staticDataFromWidget(const QWidget* w)
80 {
81  const UIntSpinBox* spin = dynamic_cast<const UIntSpinBox*> (w);
82  Q_CHECK_PTR(spin);
83  if (spin)
84  return QVariant(spin->value());
85  kWarning() << "could not cast widget";
86  return QVariant();
87 }
88 
89 template<typename T>
90 inline void UIntDataInformationMethods<T>::staticSetWidgetData(T value, QWidget* w)
91 {
92  UIntSpinBox* spin = dynamic_cast<UIntSpinBox*> (w);
93  Q_CHECK_PTR(spin);
94  if (spin)
95  spin->setValue(value);
96 }
97 
98 //explicitly instantiate all valid classes (c++-faq-lite 35.12)
99 template class UIntDataInformationMethods<quint8>;
100 template class UIntDataInformationMethods<quint16>;
101 template class UIntDataInformationMethods<quint32>;
102 template class UIntDataInformationMethods<quint64>;
UIntSpinBox
Definition: uintspinbox.h:32
UIntSpinBox::value
quint64 value() const
Definition: uintspinbox.h:78
UIntDataInformationMethods::staticDataFromWidget
static QVariant staticDataFromWidget(const QWidget *w)
Definition: uintdatainformation.cpp:79
UIntDataInformationMethods::asScriptValue
static QScriptValue asScriptValue(T value, QScriptEngine *engine, ScriptHandlerInfo *handler)
Definition: uintdatainformation.cpp:34
QWidget
structviewpreferences.h
UIntSpinBox::setMaximum
void setMaximum(quint64 max)
Definition: uintspinbox.h:81
uintdatainformation.h
UIntDataInformationMethods::staticValueString
static QString staticValueString(T val, int base=Kasten2::StructViewPreferences::unsignedDisplayBase())
Definition: uintdatainformation.cpp:51
UIntDataInformationMethods::staticSetWidgetData
static void staticSetWidgetData(T value, QWidget *w)
Definition: uintdatainformation.cpp:90
Kasten2::StructViewPreferences::localeAwareDecimalFormatting
static bool localeAwareDecimalFormatting()
Get LocaleAwareDecimalFormatting.
Definition: structviewpreferences.h:196
UIntDataInformationMethods
Definition: uintdatainformation.h:29
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
UIntDataInformationMethods::staticCreateEditWidget
static QWidget * staticCreateEditWidget(QWidget *parent)
Definition: uintdatainformation.cpp:71
UIntSpinBox::setValue
void setValue(quint64 value)
Definition: uintspinbox.h:96
PrimitiveDataInformation::basePrefix
static QString basePrefix(int base)
Definition: primitivedatainformation.h:143
Kasten2::StructViewPreferences::unsignedDisplayBase
static int unsignedDisplayBase()
Get UnsignedDisplayBase.
Definition: structviewpreferences.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal