[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info
From: Friedrich W. H. Kossebau <kossebau () kde ! org>
Date: 2008-07-01 0:50:46
Message-ID: 1214873446.938774.26595.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 826580 by kossebau:
fixed: tracking of statistic sources finally works, Update button now activated only \
if useful
M +8 -8 createstatisticjob.cpp
M +8 -5 createstatisticjob.h
M +49 -12 infotool.cpp
M +14 -2 infotool.h
M +2 -2 infoview.cpp
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info/createstatisticjob.cpp \
#826579:826580 @@ -35,16 +35,16 @@
// reset
memset( mByteCount, 0, 256*sizeof(int) );
- const int size = mByteArrayModel ? mByteArrayModel->size() : 0;
- int i = 0;
- int blockEnd = 0;
- while( i<size )
+ const int last = mByteArrayModel ? mSelection.end() : -1;
+ int i = mByteArrayModel ? mSelection.start() : 0;
+ int blockEnd = i;
+ while( i<=last )
{
blockEnd += StatisticBlockSize;
- if( blockEnd > size )
- blockEnd = size;
+ if( blockEnd > last )
+ blockEnd = last;
- for( ; i<blockEnd; ++i )
+ for( ; i<=blockEnd; ++i )
++mByteCount[(unsigned char)mByteArrayModel->datum(i)];
QApplication::processEvents( QEventLoop::ExcludeUserInputEvents | \
QEventLoop::ExcludeSocketNotifiers, 100 ); @@ -52,5 +52,5 @@
deleteLater(); // TODO: could be reused on next search
- return size;
+ return ( mByteArrayModel ? mSelection.width() : 0 );
}
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info/createstatisticjob.h \
#826579:826580 @@ -23,9 +23,10 @@
#ifndef CREATESTATISTICJOB_H
#define CREATESTATISTICJOB_H
+// Okteta core
+#include <ksection.h>
// Qt
#include <QtCore/QObject>
-#include <QtCore/QByteArray>
namespace KHECore {
class KAbstractByteArrayModel;
@@ -36,22 +37,24 @@
Q_OBJECT
public:
- CreateStatisticJob( const KHECore::KAbstractByteArrayModel *model,
+ CreateStatisticJob( const KHECore::KAbstractByteArrayModel *model, const \
KHE::KSection &selection, int *byteCount );
public:
- // return size of byte array
+ // return size of selected byte array
int exec();
protected:
const KHECore::KAbstractByteArrayModel *mByteArrayModel;
+ const KHE::KSection mSelection;
int * const mByteCount;
};
inline CreateStatisticJob::CreateStatisticJob( const \
KHECore::KAbstractByteArrayModel *model,
- int *byteCount )
- : mByteArrayModel( model ), mByteCount( byteCount )
+ const KHE::KSection &selection,
+ int *byteCount )
+ : mByteArrayModel( model ), mSelection( selection ), mByteCount( byteCount )
{}
#endif
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info/infotool.cpp \
#826579:826580 @@ -32,8 +32,6 @@
// Okteta gui
#include <kbytearrayview.h>
// Okteta core
-#include <khechar.h>
-#include <kcharcodec.h>
#include <kbytearraymodel.h>
// Qt
#include <QtGui/QApplication>
@@ -41,20 +39,29 @@
InfoTool::InfoTool()
: mStatisticTableModel( new StatisticTableModel(mByteCount,this) ),
- mByteArrayView( 0 ), mByteArrayModel( 0 )
+ mByteArrayView( 0 ), mByteArrayModel( 0 ), mSourceByteArrayModelUptodate( false \
), mSourceByteArrayModel( 0 ) {
updateStatistic();
}
StatisticTableModel *InfoTool::statisticTableModel() const { return \
mStatisticTableModel; }
-bool InfoTool::hasByteArrayView() const { return ( mByteArrayView != 0 ); }
int InfoTool::size() const { return (mByteArrayModel!=0) ? mByteArrayModel->size() : \
0; } +bool InfoTool::isApplyable() const
+{
+ return ( mByteArrayModel != 0 && mByteArrayView->hasSelectedData() && \
!isStatisticUptodate() ); +}
+bool InfoTool::isStatisticUptodate() const
+{
+ return ( mSourceByteArrayModelUptodate
+ && mSourceByteArrayModel == mByteArrayModel
+ && mByteArrayView && mSourceSelection == mByteArrayView->selection() );
+}
void InfoTool::setView( KAbstractView *view )
{
if( mByteArrayView ) mByteArrayView->disconnect( mStatisticTableModel );
- if( mByteArrayModel ) mByteArrayModel->disconnect( this );
+ if( mByteArrayView ) mByteArrayView->disconnect( this );
mByteArrayView = view ? static_cast<KHEUI::KByteArrayView *>( view->widget() ) : \
0;
@@ -69,26 +76,56 @@
mStatisticTableModel, SLOT(setCharCodec( const QString &)) );
connect( mByteArrayView, SIGNAL(valueCodingChanged( int )),
mStatisticTableModel, SLOT(setValueCoding( int )) );
- connect( mByteArrayModel, SIGNAL(modificationChanged( bool )),
- SIGNAL(statisticDirty( bool )) );
+ connect( mByteArrayView, SIGNAL(selectionChanged( bool )),
+ SLOT(onSelectionChanged( bool )) );
}
+
+ emit statisticDirty( !isStatisticUptodate() );
+ emit isApplyableChanged( isApplyable() );
+}
+
+void InfoTool::onSelectionChanged( bool hasSelection )
+{
+// TODO: could be quicker
+Q_UNUSED( hasSelection )
+ emit statisticDirty( !isStatisticUptodate() );
+ emit isApplyableChanged( isApplyable() );
+}
+
+void InfoTool::onSourceChanged()
+{
+ mSourceByteArrayModelUptodate = false;
emit statisticDirty( true );
-// updateStatistic();
- emit byteArrayViewChanged( mByteArrayView != 0 );
+ emit isApplyableChanged( isApplyable() );
}
void InfoTool::updateStatistic()
{
+ // forget old string source
+ if( mSourceByteArrayModel ) mSourceByteArrayModel->disconnect( this );
+
QApplication::setOverrideCursor( Qt::WaitCursor );
- CreateStatisticJob *createStatisticJob = new CreateStatisticJob( \
mByteArrayModel, mByteCount );
- const int size = createStatisticJob->exec();
+ const KHE::KSection selection = ( mByteArrayView ? mByteArrayView->selection() : \
KHE::KSection() ); + CreateStatisticJob *createStatisticJob =
+ new CreateStatisticJob( mByteArrayModel, selection, mByteCount );
+ const int selectionSize = createStatisticJob->exec();
QApplication::restoreOverrideCursor();
- mStatisticTableModel->update( size );
+ mStatisticTableModel->update( selectionSize );
+
+ // remember new string source
+ mSourceByteArrayModel = mByteArrayModel;
+ mSourceSelection = selection;
+ if( mSourceByteArrayModel )
+ connect( mSourceByteArrayModel, SIGNAL(contentsChanged( const \
KHE::ArrayChangeMetricsList & )), + SLOT(onSourceChanged()) );
+
+ mSourceByteArrayModelUptodate = true;
emit statisticDirty( false );
+ emit isApplyableChanged( false );
}
InfoTool::~InfoTool() {}
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info/infotool.h \
#826579:826580 @@ -23,6 +23,8 @@
#ifndef INFOTOOL_H
#define INFOTOOL_H
+// Okteta core
+#include <ksection.h>
// Qt
#include <QtCore/QObject>
@@ -52,13 +54,16 @@
public:
StatisticTableModel *statisticTableModel() const;
int size() const;
- bool hasByteArrayView() const;
+ bool isApplyable() const;
+ bool isStatisticUptodate() const;
public Q_SLOTS:
void updateStatistic();
+ void onSelectionChanged( bool hasSelection );
+ void onSourceChanged();
Q_SIGNALS:
- void byteArrayViewChanged( bool hasByteArrayView );
+ void isApplyableChanged( bool isApplyable );
void statisticDirty( bool dirty );
protected:
@@ -68,6 +73,13 @@
KHEUI::KByteArrayView *mByteArrayView;
KHECore::KAbstractByteArrayModel *mByteArrayModel;
+
+ //
+ bool mSourceByteArrayModelUptodate;
+ // selection source
+ KHE::KSection mSourceSelection;
+ // source of strings
+ KHECore::KAbstractByteArrayModel *mSourceByteArrayModel;
};
#endif
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/info/infoview.cpp \
#826579:826580 @@ -61,8 +61,8 @@
i18nc("@info:whatsthis",
"If you press the <interface>Update</interface> button, the statistic \
of the byte frequency is updated.") ); mUpdateButton = new KPushButton( \
updateGuiItem, this );
- mUpdateButton->setEnabled( mTool->hasByteArrayView() );
- connect( mTool, SIGNAL(byteArrayViewChanged(bool)), mUpdateButton, SLOT( \
setEnabled(bool )) ); + mUpdateButton->setEnabled( mTool->isApplyable() );
+ connect( mTool, SIGNAL(isApplyableChanged(bool)), mUpdateButton, SLOT( \
setEnabled(bool )) );
connect( mUpdateButton, SIGNAL(clicked(bool)), mTool, SLOT(updateStatistic()) ); \
updateLayout->addWidget( mUpdateButton );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic