• 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
  • gui
  • io
  • streamencoder
abstractbytearraystreamencoder.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2007 Friedrich W. H. Kossebau <kossebau@kde.org>
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 
23 #include "abstractbytearraystreamencoder.h"
24 
25 // lib
26 #include <bytearrayview.h>
27 #include <bytearraydocument.h>
28 #include <bytearrayselection.h>
29 // Okteta core
30 #include <abstractbytearraymodel.h>
31 // Qt
32 #include <QtCore/QBuffer>
33 
34 
35 namespace Kasten2
36 {
37 
38 static const int MaxPreviewSize = 100;
39 
40 
41 AbstractByteArrayStreamEncoder::AbstractByteArrayStreamEncoder( const QString &remoteTypeName,
42  const QString &remoteMimeType )
43  : AbstractModelStreamEncoder( remoteTypeName, remoteMimeType, QString::fromLatin1("text/plain") )
44 {}
45 
46 QString AbstractByteArrayStreamEncoder::modelTypeName( AbstractModel* model, const AbstractModelSelection* selection ) const
47 {
48 Q_UNUSED( selection )
49 
50  const ByteArrayDocument* byteArrayDocument = model->findBaseModel<const ByteArrayDocument*>();
51 
52  return ( byteArrayDocument == 0 ) ? QString() : byteArrayDocument->typeName();
53 }
54 
55 
56 bool AbstractByteArrayStreamEncoder::encodeToStream( QIODevice* device,
57  AbstractModel* model, const AbstractModelSelection* selection )
58 {
59  const ByteArrayView* byteArrayView = qobject_cast<const ByteArrayView*>( model );
60 
61  const ByteArrayDocument* byteArrayDocument =
62  byteArrayView ? qobject_cast<const ByteArrayDocument*>( byteArrayView->baseModel() ) : 0;
63  if( byteArrayDocument == 0 )
64  return false;
65 
66  const Okteta::AbstractByteArrayModel* byteArray = byteArrayDocument->content();
67 
68  const ByteArraySelection* byteArraySelection =
69  selection ? static_cast<const ByteArraySelection*>( selection ) : 0;
70 
71  const Okteta::AddressRange range = byteArraySelection && byteArraySelection->isValid() ?
72  byteArraySelection->range() :
73  Okteta::AddressRange::fromWidth( 0, byteArray->size() );
74 
75  const bool success = encodeDataToStream( device, byteArrayView, byteArray, range );
76 
77  return success;
78 }
79 
80 QString AbstractByteArrayStreamEncoder::previewData( AbstractModel* model, const AbstractModelSelection* selection )
81 {
82  const ByteArrayView* byteArrayView = qobject_cast<const ByteArrayView*>( model );
83 
84  const ByteArrayDocument* byteArrayDocument =
85  byteArrayView ? qobject_cast<const ByteArrayDocument*>( byteArrayView->baseModel() ) : 0;
86  if( byteArrayDocument == 0 )
87  return QString();
88 
89  const Okteta::AbstractByteArrayModel* byteArray = byteArrayDocument->content();
90 
91  const ByteArraySelection* byteArraySelection =
92  selection ? static_cast<const ByteArraySelection*>( selection ) : 0;
93 
94  Okteta::AddressRange range = byteArraySelection && byteArraySelection->isValid() ?
95  byteArraySelection->range() :
96  Okteta::AddressRange::fromWidth( 0, byteArray->size() );
97  range.restrictEndByWidth( MaxPreviewSize );
98 
99  QByteArray data;
100  QBuffer dataBuffer( &data );
101  dataBuffer.open( QIODevice::WriteOnly );
102 
103  const bool success = encodeDataToStream( &dataBuffer, byteArrayView, byteArray, range );
104  dataBuffer.close();
105 
106  return success ? QString::fromLatin1(data) : QString();
107 }
108 
109 AbstractByteArrayStreamEncoder::~AbstractByteArrayStreamEncoder() {}
110 
111 }
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
Kasten2::AbstractByteArrayStreamEncoder::modelTypeName
virtual QString modelTypeName(AbstractModel *model, const AbstractModelSelection *selection) const
Definition: abstractbytearraystreamencoder.cpp:46
abstractbytearraymodel.h
Kasten2::AbstractByteArrayStreamEncoder::~AbstractByteArrayStreamEncoder
virtual ~AbstractByteArrayStreamEncoder()
Definition: abstractbytearraystreamencoder.cpp:109
KDE::NumberRange< Address, Size >
Kasten2::MaxPreviewSize
static const int MaxPreviewSize
Definition: abstractbytearraystreamencoder.cpp:38
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
Kasten2::ByteArrayDocument::typeName
virtual QString typeName() const
Definition: bytearraydocument.cpp:65
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
KDE::NumberRange< Address, Size >::fromWidth
static NumberRange fromWidth(AddressstartIndex, Sizewidth)
constructs a range by width
Kasten2::ByteArraySelection::isValid
bool isValid() const
Definition: bytearrayselection.cpp:32
Kasten2::ByteArraySelection
Definition: bytearrayselection.h:37
Kasten2::ByteArraySelection::range
Okteta::AddressRange range() const
Definition: bytearrayselection.cpp:33
Kasten2::AbstractByteArrayStreamEncoder::AbstractByteArrayStreamEncoder
AbstractByteArrayStreamEncoder(const QString &remoteTypeName, const QString &remoteMimeType)
Definition: abstractbytearraystreamencoder.cpp:41
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
bytearrayselection.h
Kasten2::AbstractModel::findBaseModel
T findBaseModel() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:93
abstractbytearraystreamencoder.h
Kasten2::AbstractModelStreamEncoder
Definition: abstractmodelstreamencoder.h:50
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
bytearraydocument.h
QIODevice
KDE::NumberRange::restrictEndByWidth
void restrictEndByWidth(S width)
restricts the end by width.
Definition: numberrange.h:162
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::AbstractByteArrayStreamEncoder::encodeToStream
virtual bool encodeToStream(QIODevice *device, AbstractModel *model, const AbstractModelSelection *selection)
Definition: abstractbytearraystreamencoder.cpp:56
Kasten2::AbstractByteArrayStreamEncoder::encodeDataToStream
virtual bool encodeDataToStream(QIODevice *device, const ByteArrayView *byteArrayView, const Okteta::AbstractByteArrayModel *byteArrayModel, const Okteta::AddressRange &range)=0
Kasten2::AbstractByteArrayStreamEncoder::previewData
QString previewData(AbstractModel *model, const AbstractModelSelection *selection)
Definition: abstractbytearraystreamencoder.cpp:80
bytearrayview.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:06 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