~ubuntu-branches/ubuntu/maverick/kdeutils/maverick-proposed

« back to all changes in this revision

Viewing changes to okteta/kasten/controllers/view/structures/datatypes/datainformation.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-05-28 09:49:30 UTC
  • mfrom: (1.2.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100528094930-jzynf0obv1n2v13a
Tags: 4:4.4.80-0ubuntu1~ppa1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *   This file is part of the Okteta Kasten module, part of the KDE project.
 
2
 *   This file is part of the Okteta Kasten Framework, part of the KDE project.
3
3
 *
4
 
 *   Copyright 2009 Alex Richardson <alex.richardson@gmx.de>
 
4
 *   Copyright 2009, 2010 Alex Richardson <alex.richardson@gmx.de>
5
5
 *
6
6
 *   This library is free software; you can redistribute it and/or
7
7
 *   modify it under the terms of the GNU Lesser General Public
26
26
#include "uniondatainformation.h"
27
27
#include "primitivedatainformation.h"
28
28
#include "staticlengtharraydatainformation.h"
 
29
#include "topleveldatainformation.h"
29
30
 
30
31
DataInformation::DataInformation(const QString& name, int index,
31
32
        DataInformation* parent) :
32
 
    QObject(parent), mIndex(index)
 
33
    QObject(parent), mIndex(index), mValidationSuccessful(false), mHasBeenValidated(
 
34
            false), mWasAbleToRead(false), mAdditionalData(NULL)
33
35
{
34
36
    setObjectName(name);
35
37
}
36
38
 
37
39
DataInformation::DataInformation(const DataInformation& d) :
38
 
    QObject(NULL), mIndex(d.mIndex)
 
40
    QObject(NULL), QScriptable(), mIndex(d.mIndex), mValidationSuccessful(d.mValidationSuccessful),
 
41
            mHasBeenValidated(d.mHasBeenValidated),
 
42
            mWasAbleToRead(d.mWasAbleToRead), mAdditionalData(NULL)
39
43
{
40
44
    setObjectName(d.objectName());
 
45
    if (d.mAdditionalData)
 
46
        mAdditionalData = new AdditionalData(*(d.mAdditionalData));
41
47
}
42
48
 
43
49
DataInformation::~DataInformation()
44
50
{
 
51
    delete mAdditionalData;
45
52
}
46
53
 
47
 
QString DataInformation::getValueString() const
 
54
QString DataInformation::valueString() const
48
55
{
49
56
    return QString();
50
57
}
51
58
 
52
 
QString DataInformation::getSizeString() const
 
59
QString DataInformation::sizeString() const
53
60
{
54
 
    return i18np("1 byte", "%1 bytes", getSize() / 8);
55
 
    //  return KGlobal::locale()->formatByteSize(getSize() / 8);
56
 
 
 
61
    if (size() % 8 == 0) //no bits remaining
 
62
    {
 
63
        return i18np("1 byte", "%1 bytes", size() / 8);
 
64
    }
 
65
    else
 
66
    {
 
67
        QString bytes = i18np("1 byte", "%1 bytes", size() / 8);
 
68
        QString bits = i18np("1 bit", "%1 bits", size() % 8);
 
69
        return i18nc("number of bytes, then number of bits", "%1 %2", bytes, bits);
 
70
    }
57
71
}
58
72
 
59
 
Okteta::Size DataInformation::positionRelativeToParent() const
 
73
quint64 DataInformation::positionRelativeToParent() const
60
74
{
61
 
    DataInformation* par = static_cast<DataInformation*> (parent());
 
75
    //FIXME this needs updating to support bitfield marking
 
76
    DataInformation* par = dynamic_cast<DataInformation*> (parent());
62
77
    if (!par)
63
78
    {
64
79
        return 0;
65
80
    }
66
81
    return par->offset(this->mIndex) + par->positionRelativeToParent();
67
82
}
 
83
 
 
84
void DataInformation::setIndex(int newIndex)
 
85
{
 
86
    mIndex = newIndex;
 
87
}
 
88
 
 
89
TopLevelDataInformation* DataInformation::topLevelDataInformation() const
 
90
{
 
91
    DataInformation* par = dynamic_cast<DataInformation*> (parent());
 
92
    if (par)
 
93
        return par->topLevelDataInformation();
 
94
    else
 
95
    {
 
96
        TopLevelDataInformation* top =
 
97
                dynamic_cast<TopLevelDataInformation*> (parent());
 
98
        if (top)
 
99
            return top;
 
100
    }
 
101
    return NULL;
 
102
}
 
103
 
 
104
DataInformation* DataInformation::mainStructure()
 
105
{
 
106
    DataInformation* par = dynamic_cast<DataInformation*> (parent());
 
107
    if (par)
 
108
        return par->mainStructure();
 
109
    else
 
110
        return this;
 
111
 
 
112
}
 
113
 
 
114
void DataInformation::setAdditionalData(AdditionalData* data)
 
115
{
 
116
    mAdditionalData = data;
 
117
}
 
118
 
 
119
QString DataInformation::validationError() const
 
120
{
 
121
    if (!mAdditionalData)
 
122
        return QString();
 
123
    return mAdditionalData->validationError();
 
124
}
 
125
 
 
126
void DataInformation::setValidationError(QString errorMessage)
 
127
{
 
128
    setValidationSuccessful(false);
 
129
    if (!mAdditionalData)
 
130
        mAdditionalData = new AdditionalData();
 
131
    mAdditionalData->setValidationError(errorMessage);
 
132
}
 
133
 
 
134
bool DataInformation::validationSuccessful() const
 
135
{
 
136
    return mValidationSuccessful;
 
137
}
 
138
 
 
139
void DataInformation::setValidationSuccessful(bool successful)
 
140
{
 
141
    mValidationSuccessful = successful;
 
142
    setHasBeenValidated(true);
 
143
}
 
144
 
 
145
bool DataInformation::hasBeenValidated() const
 
146
{
 
147
    return mHasBeenValidated;
 
148
}
 
149
 
 
150
void DataInformation::setHasBeenValidated(bool hasBeen)
 
151
{
 
152
    mHasBeenValidated = hasBeen;
 
153
}
 
154
 
 
155
void DataInformation::resetValidationState()
 
156
{
 
157
    mHasBeenValidated = false;
 
158
    mValidationSuccessful = false;
 
159
    if (mAdditionalData)
 
160
        mAdditionalData->setValidationError(QString());
 
161
}
 
162
void DataInformation::beginRead()
 
163
{
 
164
    for (uint i = 0; i < childCount(); ++i)
 
165
    {
 
166
        childAt(i)->beginRead();
 
167
    }
 
168
    mWasAbleToRead = false;
 
169
}
 
170