• 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
sintdatainformation.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 "sintdatainformation.h"
23 #include "../poddecoder/typeeditors/sintspinbox.h"
24 
25 #include <QScriptValue>
26 #include <KGlobal>
27 #include <KLocale>
28 #include <KDebug>
29 
30 template<typename T>
31 QString SIntDataInformationMethods<T>::staticValueString(T val, int base)
32 {
33  QString num;
34  if (base == 10)
35  {
36  num = QString::number(val, base);
37  if (Kasten2::StructViewPreferences::localeAwareDecimalFormatting())
38  num = KGlobal::locale()->formatNumber(num, false, 0);
39  return num;
40  }
41  //the absolute value of negative minimum can not be represented as a signed integer
42  //casting it to an unsigned value yields the correct result
43  if (val == std::numeric_limits<T>::min())
44  num = QString::number(typename QIntegerForSizeof<T>::Unsigned(val), base);
45  else if (val < 0)
46  num = QString::number(qAbs(val), base);
47  else
48  num = QString::number(val, base);
49  //TODO non decimal negative values as unsigned? probably add option
50  //add one space every 8 chars
51  for (int i = 8; i < num.length(); i += 9)
52  {
53  num.insert(num.length() - i, QLatin1Char(' '));
54  }
55  if (val < 0)
56  return QLatin1Char('-') + PrimitiveDataInformation::basePrefix(base) + num;
57  else
58  return PrimitiveDataInformation::basePrefix(base) + num;
59 }
60 
61 template<typename T>
62 QScriptValue SIntDataInformationMethods<T>::asScriptValue(T value, QScriptEngine* engine,
63  ScriptHandlerInfo* handler)
64 {
65  Q_UNUSED(engine);
66  Q_UNUSED(handler);
67  return QScriptValue(value);
68 }
69 
70 template<>
71 QScriptValue SIntDataInformationMethods<qint64>::asScriptValue(qint64 value, QScriptEngine* engine,
72  ScriptHandlerInfo* handler)
73 {
74  Q_UNUSED(engine);
75  Q_UNUSED(handler);
76  return QScriptValue(QString::number(value, 10));
77 }
78 
79 template<typename T>
80 inline QWidget* SIntDataInformationMethods<T>::staticCreateEditWidget(QWidget* parent)
81 {
82  SIntSpinBox* ret = new SIntSpinBox(parent, Kasten2::StructViewPreferences::signedDisplayBase());
83  ret->setRange(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
84  return ret;
85 }
86 
87 template<typename T>
88 inline QVariant SIntDataInformationMethods<T>::staticDataFromWidget(const QWidget* w)
89 {
90  const SIntSpinBox* spin = dynamic_cast<const SIntSpinBox*>(w);
91  Q_CHECK_PTR(spin);
92  if (spin)
93  return spin->value();
94 
95  kWarning() << "could not cast widget";
96  return QVariant();
97 }
98 
99 template<typename T>
100 inline void SIntDataInformationMethods<T>::staticSetWidgetData(T value, QWidget* w)
101 {
102  SIntSpinBox* spin = dynamic_cast<SIntSpinBox*>(w);
103  Q_CHECK_PTR(spin);
104  if (spin)
105  spin->setValue(value);
106 }
107 
108 //explicitly instantiate all valid classes (c++-faq-lite 35.12)
109 template class SIntDataInformationMethods<qint8>;
110 template class SIntDataInformationMethods<qint16>;
111 template class SIntDataInformationMethods<qint32>;
112 template class SIntDataInformationMethods<qint64>;
SIntDataInformationMethods
Definition: sintdatainformation.h:29
SIntSpinBox::value
qint64 value() const
Definition: sintspinbox.h:78
SIntSpinBox::setRange
void setRange(qint64 minimum, qint64 maximum)
Definition: sintspinbox.h:95
QWidget
SIntDataInformationMethods::staticValueString
static QString staticValueString(T val, int base=Kasten2::StructViewPreferences::signedDisplayBase())
Definition: sintdatainformation.cpp:31
SIntSpinBox
Definition: sintspinbox.h:32
SIntDataInformationMethods::asScriptValue
static QScriptValue asScriptValue(T value, QScriptEngine *engine, ScriptHandlerInfo *handler)
Definition: sintdatainformation.cpp:62
SIntDataInformationMethods::staticDataFromWidget
static QVariant staticDataFromWidget(const QWidget *w)
Definition: sintdatainformation.cpp:88
sintdatainformation.h
SIntDataInformationMethods::staticCreateEditWidget
static QWidget * staticCreateEditWidget(QWidget *parent)
Definition: sintdatainformation.cpp:80
Kasten2::StructViewPreferences::signedDisplayBase
static int signedDisplayBase()
Get SignedDisplayBase.
Definition: structviewpreferences.h:61
Kasten2::StructViewPreferences::localeAwareDecimalFormatting
static bool localeAwareDecimalFormatting()
Get LocaleAwareDecimalFormatting.
Definition: structviewpreferences.h:196
SIntSpinBox::setValue
void setValue(qint64 value)
Definition: sintspinbox.h:80
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
SIntDataInformationMethods::staticSetWidgetData
static void staticSetWidgetData(T value, QWidget *w)
Definition: sintdatainformation.cpp:100
PrimitiveDataInformation::basePrefix
static QString basePrefix(int base)
Definition: primitivedatainformation.h:143
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