• 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
  • filter
filtertool.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 2008 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 "filtertool.h"
24 
25 // tool
26 #include "filterjob.h"
27 // filter
28 #include <bytearrayfilterfactory.h>
29 #include <abstractbytearrayfilter.h>
30 // lib
31 #include <bytearrayview.h>
32 #include <bytearraydocument.h>
33 // Okteta core
34 #include <abstractbytearraymodel.h>
35 #include <changesdescribable.h>
36 // KDE
37 #include <KLocale>
38 // Qt
39 #include <QtGui/QApplication>
40 #include <QtCore/QByteArray>
41 
42 
43 namespace Kasten2
44 {
45 
46 FilterTool::FilterTool()
47  : mByteArrayView( 0 ), mByteArrayModel( 0 ), mHasWritable( false )
48 {
49  setObjectName( QLatin1String( "BinaryFilter" ) );
50 
51  mFilterList = ByteArrayFilterFactory::createFilters();
52 }
53 
54 QString FilterTool::title() const { return i18nc("@title:window", "Binary Filter"); }
55 QList<AbstractByteArrayFilter*> FilterTool::filterList() const { return mFilterList; }
56 QString FilterTool::charCodecName() const
57 {
58  return mByteArrayView ? mByteArrayView->charCodingName() : QString();
59 }
60 
61 bool FilterTool::hasWriteable() const { return mHasWritable; }
62 
63 AbstractByteArrayFilterParameterSet *FilterTool::parameterSet( int filterId )
64 {
65  AbstractByteArrayFilter *byteArrayFilter = mFilterList.at( filterId );
66 
67  return byteArrayFilter ? byteArrayFilter->parameterSet() : 0;
68 }
69 
70 void FilterTool::setTargetModel( AbstractModel* model )
71 {
72  if( mByteArrayView ) mByteArrayView->disconnect( this );
73 
74  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
75 
76  ByteArrayDocument *document =
77  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
78  mByteArrayModel = document ? document->content() : 0;
79 
80  const bool hasByteArray = ( mByteArrayModel && mByteArrayView );
81  QString newCharCodecName;
82  if( hasByteArray )
83  {
84  newCharCodecName = mByteArrayView->charCodingName();
85  connect( mByteArrayView, SIGNAL(hasSelectedDataChanged(bool)), SLOT(onApplyableChanged()) );
86  connect( mByteArrayView, SIGNAL(readOnlyChanged(bool)), SLOT(onApplyableChanged()) );
87  connect( mByteArrayView, SIGNAL(charCodecChanged(QString)),
88  SIGNAL(charCodecChanged(QString)) );
89  }
90 
91  onApplyableChanged();
92  emit charCodecChanged( newCharCodecName );
93 }
94 
95 
96 void FilterTool::filter( int filterId ) const
97 {
98  AbstractByteArrayFilter *byteArrayFilter = mFilterList.at( filterId );
99 
100  if( byteArrayFilter )
101  {
102  const Okteta::AddressRange filteredSection = mByteArrayView->selection();
103 
104  QByteArray filterResult;
105  filterResult.resize( filteredSection.width() );
106 
107  QApplication::setOverrideCursor( Qt::WaitCursor );
108 
109  FilterJob* filterJob = new FilterJob( byteArrayFilter, reinterpret_cast<Okteta::Byte*>(filterResult.data()), mByteArrayModel, filteredSection );
110  const bool success = filterJob->exec();
111 
112  QApplication::restoreOverrideCursor();
113 
114  if( success )
115  {
116  Okteta::ChangesDescribable *changesDescribable =
117  qobject_cast<Okteta::ChangesDescribable*>( mByteArrayModel );
118 
119  if( changesDescribable )
120  changesDescribable->openGroupedChange( byteArrayFilter->name() );
121  mByteArrayModel->replace( filteredSection, filterResult );
122  if( changesDescribable )
123  changesDescribable->closeGroupedChange();
124  }
125  }
126 
127  mByteArrayView->setFocus();
128 }
129 
130 void FilterTool::onApplyableChanged()
131 {
132  const bool newHasWriteable = ( mByteArrayModel && mByteArrayView
133  && !mByteArrayView->isReadOnly() && mByteArrayView->hasSelectedData() );
134  if( newHasWriteable != mHasWritable )
135  {
136  mHasWritable = newHasWriteable;
137  emit hasWriteableChanged( newHasWriteable );
138  }
139 }
140 
141 FilterTool::~FilterTool()
142 {
143  qDeleteAll( mFilterList );
144 }
145 
146 }
Kasten2::ByteArrayView::setFocus
virtual void setFocus()
Definition: bytearrayview.cpp:155
filterjob.h
Okteta::AbstractByteArrayModel::replace
virtual Size replace(const AddressRange &removeRange, const Byte *insertData, int insertLength)=0
replaces as much as possible
abstractbytearraymodel.h
Kasten2::FilterTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: filtertool.cpp:70
Okteta::ChangesDescribable::closeGroupedChange
virtual void closeGroupedChange(const QString &description=QString())=0
Kasten2::FilterTool::~FilterTool
virtual ~FilterTool()
Definition: filtertool.cpp:141
Kasten2::FilterTool::hasWriteable
bool hasWriteable() const
Definition: filtertool.cpp:61
Kasten2::ByteArrayView::charCodingName
QString charCodingName() const
Definition: bytearrayview.cpp:255
KDE::NumberRange< Address, Size >
Kasten2::FilterTool::title
virtual QString title() const
Definition: filtertool.cpp:54
AbstractByteArrayFilter::parameterSet
virtual AbstractByteArrayFilterParameterSet * parameterSet()=0
used by the editor to get write access to the parameters
Okteta::ChangesDescribable::openGroupedChange
virtual void openGroupedChange(const QString &description=QString())=0
Kasten2::FilterTool::filterList
QList< AbstractByteArrayFilter * > filterList() const
Definition: filtertool.cpp:55
Okteta::ChangesDescribable
Definition: changesdescribable.h:33
AbstractByteArrayFilter
Definition: abstractbytearrayfilter.h:39
Kasten2::ByteArrayView::hasSelectedData
virtual bool hasSelectedData() const
Definition: bytearrayview.cpp:178
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
KDE::NumberRange::width
S width() const
Definition: numberrange.h:141
abstractbytearrayfilter.h
filtertool.h
Kasten2::ByteArrayView::selection
Okteta::AddressRange selection() const
Definition: bytearrayview.cpp:271
Kasten2::FilterTool::charCodecChanged
void charCodecChanged(const QString &charCodecName)
ByteArrayFilterFactory::createFilters
static QList< AbstractByteArrayFilter * > createFilters()
Definition: bytearrayfilterfactory.cpp:40
Kasten2::FilterTool::parameterSet
AbstractByteArrayFilterParameterSet * parameterSet(int filterId)
Definition: filtertool.cpp:63
AbstractByteArrayFilter::name
QString name() const
Definition: abstractbytearrayfilter.cpp:50
Kasten2::FilterTool::filter
void filter(int filterId) const
Definition: filtertool.cpp:96
Kasten2::FilterTool::FilterTool
FilterTool()
Definition: filtertool.cpp:46
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
changesdescribable.h
Kasten2::FilterTool::charCodecName
QString charCodecName() const
Definition: filtertool.cpp:56
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
AbstractByteArrayFilterParameterSet
Definition: abstractbytearrayfilterparameterset.h:27
bytearrayfilterfactory.h
bytearraydocument.h
Kasten2::FilterJob
Definition: filterjob.h:42
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::FilterTool::hasWriteableChanged
void hasWriteableChanged(bool hasWriteable)
Kasten2::FilterJob::exec
bool exec()
Definition: filterjob.cpp:36
Kasten2::ByteArrayView::isReadOnly
virtual bool isReadOnly() const
default returns true
Definition: bytearrayview.cpp:152
QList< AbstractByteArrayFilter * >
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:08 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