• 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
  • info
infotool.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 "infotool.h"
24 
25 // controller
26 #include "statistictablemodel.h"
27 #include "createstatisticjob.h"
28 // lib
29 #include <bytearrayview.h>
30 #include <bytearraydocument.h>
31 // Okteta core
32 #include <abstractbytearraymodel.h>
33 // KDE
34 #include <KLocale>
35 // Qt
36 #include <QtGui/QApplication>
37 
38 
39 namespace Kasten2
40 {
41 
42 InfoTool::InfoTool()
43  : mStatisticTableModel( new StatisticTableModel(mByteCount,this) ),
44  mByteArrayView( 0 ), mByteArrayModel( 0 ), mSourceByteArrayModelUptodate( false ), mSourceByteArrayModel( 0 )
45 {
46  setObjectName( QLatin1String( "Info" ) );
47  updateStatistic();
48 }
49 
50 QString InfoTool::title() const { return i18nc("@title:window", "Statistics"); }
51 StatisticTableModel *InfoTool::statisticTableModel() const { return mStatisticTableModel; }
52 int InfoTool::size() const { return (mByteArrayModel!=0) ? mByteArrayModel->size() : -1; }
53 bool InfoTool::isApplyable() const
54 {
55  return ( mByteArrayModel && mByteArrayView && mByteArrayView->hasSelectedData() && !isStatisticUptodate() );
56 }
57 bool InfoTool::isStatisticUptodate() const
58 {
59  return ( mSourceByteArrayModelUptodate
60  && mSourceByteArrayModel == mByteArrayModel
61  && mByteArrayView && mSourceSelection == mByteArrayView->selection() );
62 }
63 
64 
65 void InfoTool::setTargetModel( AbstractModel* model )
66 {
67  if( mByteArrayView )
68  {
69  mByteArrayView->disconnect( mStatisticTableModel );
70  mByteArrayView->disconnect( this );
71  }
72 
73  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
74 
75  ByteArrayDocument* document =
76  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
77  mByteArrayModel = document ? document->content() : 0;
78 
79  if( mByteArrayView && mByteArrayModel )
80  {
81  mStatisticTableModel->setCharCodec( mByteArrayView->charCodingName() );
82  mStatisticTableModel->setValueCoding( mByteArrayView->valueCoding() );
83  mStatisticTableModel->setUndefinedChar( mByteArrayView->undefinedChar() );
84  connect( mByteArrayView, SIGNAL(charCodecChanged(QString)),
85  mStatisticTableModel, SLOT(setCharCodec(QString)) );
86  connect( mByteArrayView, SIGNAL(valueCodingChanged(int)),
87  mStatisticTableModel, SLOT(setValueCoding(int)) );
88  connect( mByteArrayView, SIGNAL(undefinedCharChanged(QChar)),
89  mStatisticTableModel, SLOT(setUndefinedChar(QChar)) );
90 
91  connect( mByteArrayView, SIGNAL(selectedDataChanged(const Kasten2::AbstractModelSelection*)),
92  SLOT(onSelectionChanged()) );
93  }
94 
95  emit statisticDirty( !isStatisticUptodate() );
96  emit isApplyableChanged( isApplyable() );
97 }
98 
99 void InfoTool::onSelectionChanged()
100 {
101 // TODO: could be quicker using the selection data
102  emit statisticDirty( !isStatisticUptodate() );
103  emit isApplyableChanged( isApplyable() );
104 }
105 
106 void InfoTool::onSourceChanged()
107 {
108  mSourceByteArrayModelUptodate = false;
109  emit statisticDirty( true );
110  emit isApplyableChanged( isApplyable() );
111 }
112 
113 void InfoTool::onSourceDestroyed()
114 {
115  mSourceByteArrayModel = 0;
116  onSourceChanged();
117 }
118 
119 void InfoTool::updateStatistic()
120 {
121  // forget old string source
122  if( mSourceByteArrayModel ) mSourceByteArrayModel->disconnect( this );
123 
124  QApplication::setOverrideCursor( Qt::WaitCursor );
125 
126  const Okteta::AddressRange selection = ( mByteArrayView ? mByteArrayView->selection() : Okteta::AddressRange() );
127  CreateStatisticJob *createStatisticJob =
128  new CreateStatisticJob( mByteArrayModel, selection, mByteCount );
129  const int selectionSize = createStatisticJob->exec();
130 
131  QApplication::restoreOverrideCursor();
132 
133  mStatisticTableModel->update( selectionSize );
134 
135  // remember new string source
136  mSourceByteArrayModel = mByteArrayModel;
137  mSourceSelection = selection;
138  if( mSourceByteArrayModel )
139  {
140  connect( mSourceByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)),
141  SLOT(onSourceChanged()) );
142  connect( mSourceByteArrayModel, SIGNAL(destroyed()),
143  SLOT(onSourceDestroyed()) );
144  }
145 
146  mSourceByteArrayModelUptodate = true;
147  emit statisticDirty( false );
148  emit isApplyableChanged( false );
149 
150  if( mByteArrayView )
151  mByteArrayView->setFocus();
152 }
153 
154 InfoTool::~InfoTool() {}
155 
156 }
Kasten2::ByteArrayView::setFocus
virtual void setFocus()
Definition: bytearrayview.cpp:155
abstractbytearraymodel.h
Kasten2::InfoTool::isApplyableChanged
void isApplyableChanged(bool isApplyable)
Kasten2::ByteArrayView::valueCoding
int valueCoding() const
Definition: bytearrayview.cpp:250
Kasten2::ByteArrayView::charCodingName
QString charCodingName() const
Definition: bytearrayview.cpp:255
KDE::NumberRange< Address, Size >
infotool.h
Kasten2::InfoTool::title
virtual QString title() const
Definition: infotool.cpp:50
Kasten2::InfoTool::updateStatistic
void updateStatistic()
Definition: infotool.cpp:119
Kasten2::InfoTool::size
int size() const
Definition: infotool.cpp:52
Kasten2::InfoTool::statisticDirty
void statisticDirty(bool dirty)
Kasten2::ByteArrayView::hasSelectedData
virtual bool hasSelectedData() const
Definition: bytearrayview.cpp:178
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
Kasten2::InfoTool::isStatisticUptodate
bool isStatisticUptodate() const
Definition: infotool.cpp:57
Kasten2::ByteArrayView::selection
Okteta::AddressRange selection() const
Definition: bytearrayview.cpp:271
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
Kasten2::StatisticTableModel
Definition: statistictablemodel.h:40
Kasten2::StatisticTableModel::setUndefinedChar
void setUndefinedChar(QChar undefinedChar)
Definition: statistictablemodel.cpp:60
Kasten2::InfoTool::~InfoTool
virtual ~InfoTool()
Definition: infotool.cpp:154
Okteta::ArrayChangeMetricsList
Definition: arraychangemetricslist.h:36
Kasten2::InfoTool::InfoTool
InfoTool()
Definition: infotool.cpp:42
Kasten2::StatisticTableModel::update
void update(int size)
Definition: statistictablemodel.cpp:53
Kasten2::StatisticTableModel::setValueCoding
void setValueCoding(int valueCoding)
Definition: statistictablemodel.cpp:67
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
Okteta::AddressRange
KDE::NumberRange< Address, Size > AddressRange
Definition: addressrange.h:35
statistictablemodel.h
Kasten2::InfoTool::isApplyable
bool isApplyable() const
Definition: infotool.cpp:53
Kasten2::ByteArrayView::undefinedChar
QChar undefinedChar() const
Definition: bytearrayview.cpp:373
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
Kasten2::InfoTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: infotool.cpp:65
Kasten2::StatisticTableModel::setCharCodec
void setCharCodec(const QString &codecName)
Definition: statistictablemodel.cpp:83
createstatisticjob.h
Kasten2::InfoTool::statisticTableModel
StatisticTableModel * statisticTableModel() const
Definition: infotool.cpp:51
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
bytearraydocument.h
Kasten2::CreateStatisticJob::exec
int exec()
Definition: createstatisticjob.cpp:36
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::CreateStatisticJob
Definition: createstatisticjob.h:39
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