[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeutils/okteta/program/oktetakakao/controllers/view/stringsextract
From:       Friedrich W. H. Kossebau <kossebau () kde ! org>
Date:       2008-06-30 23:19:05
Message-ID: 1214867945.966503.24159.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 826557 by kossebau:

fixed: tracking of string sources finally works, Update button now activated only if useful

 M  +40 -19    stringsextracttool.cpp  
 M  +12 -5     stringsextracttool.h  
 M  +14 -13    stringsextractview.cpp  
 M  +1 -1      stringsextractview.h  


--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/stringsextract/stringsextracttool.cpp #826556:826557
@@ -39,20 +39,21 @@
 static const int DefaultMinLength = 3;
 
 StringsExtractTool::StringsExtractTool()
- : mCharCodec( KHECore::KCharCodec::createCodec(KHECore::LocalEncoding) ), mMinLength( DefaultMinLength ),
-   mByteArrayView( 0 ), mByteArrayModel( 0 ), mSourceByteArrayModel( 0 )
+ : mExtractedStringsUptodate( false ), mSourceByteArrayModelUptodate( false ),
+   mCharCodec( KHECore::KCharCodec::createCodec(KHECore::LocalEncoding) ), mMinLength( DefaultMinLength ),
+   mByteArrayView( 0 ), mByteArrayModel( 0 ), mSourceByteArrayModel( 0 ), mSourceMinLength( 0 )
 {
 }
 
 bool StringsExtractTool::isApplyable() const
 {
-    return ( mByteArrayModel != 0 && mByteArrayView->hasSelectedData() );
+    return ( mByteArrayModel != 0 && mByteArrayView->hasSelectedData() && mMinLength > 0 );
 }
 
-bool StringsExtractTool::isSelectable() const
+bool StringsExtractTool::canHighlightString() const
 {
     return ( mSourceByteArrayModel == mByteArrayModel
-             && mByteArrayView && mByteArrayView->selection() == mSourceSelection );
+             && mByteArrayView && mSourceByteArrayModelUptodate );
 }
 
 // TODO: add model with offset and string
@@ -63,7 +64,6 @@
 void StringsExtractTool::setView( KAbstractView *view )
 {
     if( mByteArrayView ) mByteArrayView->disconnect( this );
-    if( mByteArrayModel ) mByteArrayModel->disconnect( this );
 
     mByteArrayView = view ? static_cast<KHEUI::KByteArrayView *>( view->widget() ) : 0;
 
@@ -75,22 +75,24 @@
         connect( mByteArrayView,  SIGNAL(charCodecChanged( const QString & )),
                  SLOT(setCharCodec( const QString &)) );
         connect( mByteArrayView,  SIGNAL(selectionChanged( bool )),
-                 SIGNAL(isApplyableChanged( bool )) );
+                 SLOT(onSelectionChanged( bool )) );
 
         setCharCodec( mByteArrayView->encodingName() );
     }
 
     // TODO: if there is no view, there is nothing to extract.
     // or this could be the view where we got the strings from and it did not change
+    checkUptoDate();
+    emit uptodateChanged( mExtractedStringsUptodate );
     emit isApplyableChanged( isApplyable() );
-    emit isSelectableChanged( isSelectable() );
+    emit canHighlightStringChanged( canHighlightString() );
 }
 
 void StringsExtractTool::setMinLength( int minLength )
 {
     mMinLength = minLength;
-    mUptodate = false;
-    emit uptodateChanged( false );
+    checkUptoDate();
+    emit uptodateChanged( mExtractedStringsUptodate );
 }
 
 void StringsExtractTool::setCharCodec( const QString &codecName )
@@ -102,6 +104,15 @@
     mCharCodec = KHECore::KCharCodec::createCodec( codecName );
 }
 
+void StringsExtractTool::checkUptoDate()
+{
+    mExtractedStringsUptodate =
+        ( mSourceByteArrayModel == mByteArrayModel
+          && mByteArrayView && mSourceSelection == mByteArrayView->selection()
+          && mSourceMinLength == mMinLength
+          && mSourceByteArrayModelUptodate );
+}
+
 void StringsExtractTool::selectString( int stringId )
 {
     const ContainedString &containedString = mContainedStringList.at(stringId);
@@ -111,11 +122,21 @@
     mByteArrayView->setFocus();
 }
 
-void StringsExtractTool::onSourceModified()
+void StringsExtractTool::onSelectionChanged( bool hasSelection )
 {
-    mUptodate = false;
+// TODO: could be quicker
+Q_UNUSED( hasSelection )
+    checkUptoDate();
+    emit uptodateChanged( mExtractedStringsUptodate );
+    emit isApplyableChanged( isApplyable() );
+}
+
+void StringsExtractTool::onSourceChanged()
+{
+    mExtractedStringsUptodate = false;
+    mSourceByteArrayModelUptodate = false;
     emit uptodateChanged( false );
-    emit isSelectableChanged( false );
+    emit canHighlightStringChanged( false );
 }
 
 
@@ -137,14 +158,14 @@
     // remember new string source
     mSourceByteArrayModel = mByteArrayModel;
     mSourceSelection = mByteArrayView->selection();
-    connect( mSourceByteArrayModel,  SIGNAL(modificationChanged( bool )),
-             SLOT(onSourceModified()) );
-    connect( mByteArrayView,  SIGNAL(selectionChanged( bool )),
-             SLOT(onSourceModified()) );
+    mSourceMinLength = mMinLength;
+    connect( mSourceByteArrayModel,  SIGNAL(contentsChanged( const KHE::ArrayChangeMetricsList & )),
+             SLOT(onSourceChanged()) );
 
-    mUptodate = true;
+    mExtractedStringsUptodate = true;
+    mSourceByteArrayModelUptodate = true;
     emit uptodateChanged( true );
-    emit isSelectableChanged( true );
+    emit canHighlightStringChanged( true );
 }
 
 
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/stringsextract/stringsextracttool.h #826556:826557
@@ -59,7 +59,7 @@
     int minLength() const;
     bool isApplyable() const; // candidate for AbstractTool API
     bool isUptodate() const;
-    bool isSelectable() const;
+    bool canHighlightString() const;
 
   public Q_SLOTS: // settings
     void setCharCodec( const QString &codecName );
@@ -70,16 +70,21 @@
     void extractStrings();
 
   public Q_SLOTS: // actions
-    void onSourceModified();
+    void onSelectionChanged( bool hasSelection );
+    void onSourceChanged();
 
   Q_SIGNALS:
     void uptodateChanged( bool isUptodate );
     void isApplyableChanged( bool isApplyable );  // candidate for AbstractTool API
-    void isSelectableChanged( bool isSelectable );
+    void canHighlightStringChanged( bool canHighlightString );
 
+  protected:
+    void checkUptoDate();
+
   protected: // created data
     QList<ContainedString> mContainedStringList;
-    bool mUptodate;
+    bool mExtractedStringsUptodate:1;
+    bool mSourceByteArrayModelUptodate:1;
 
   protected: // settings
     KHECore::KCharCodec *mCharCodec;
@@ -94,10 +99,12 @@
     KHE::KSection mSourceSelection;
     // source of strings
     KHECore::KAbstractByteArrayModel *mSourceByteArrayModel;
+    // minLength source
+    int mSourceMinLength;
 };
 
 inline const QList<ContainedString> *StringsExtractTool::containedStringList() const { return &mContainedStringList; }
 inline int StringsExtractTool::minLength()     const { return mMinLength; }
-inline bool StringsExtractTool::isUptodate()   const { return mUptodate; }
+inline bool StringsExtractTool::isUptodate()   const { return mExtractedStringsUptodate; }
 
 #endif
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/stringsextract/stringsextractview.cpp #826556:826557
@@ -42,6 +42,7 @@
 #include <QtGui/QClipboard>
 #include <QtGui/QApplication>
 
+
 static const int MinimumStringLength = 1;
 
 StringsExtractView::StringsExtractView( StringsExtractTool *tool, QWidget *parent )
@@ -150,7 +151,7 @@
 
     connect( mTool, SIGNAL(uptodateChanged( bool )), SLOT(onStringsUptodateChanged( bool )) );
     connect( mTool, SIGNAL(isApplyableChanged( bool )), SLOT( onApplyableChanged( bool )) );
-    connect( mTool, SIGNAL(isSelectableChanged( bool )), SLOT(onIsSelectableChanged( bool )) );
+    connect( mTool, SIGNAL(canHighlightStringChanged( bool )), SLOT(onCanHighlightStringChanged( bool )) );
 
     onStringSelectionChanged();
 }
@@ -167,22 +168,22 @@
     if( stringsUptodate )
         mContainedStringTableModel->update();
 
-    mUpdateButton->setEnabled( !stringsUptodate && mTool->isApplyable() );
+    const bool isApplyable = mTool->isApplyable();
+    mUpdateButton->setEnabled( !stringsUptodate && isApplyable );
 }
 
 void StringsExtractView::onApplyableChanged( bool isApplyable )
 {
-    mUpdateButton->setEnabled( isApplyable );
+    mUpdateButton->setEnabled( !mTool->isUptodate() && isApplyable );
 }
 
-void StringsExtractView::onIsSelectableChanged( bool isSelectable )
+void StringsExtractView::onCanHighlightStringChanged( bool canHighlightString )
 {
-    const bool hasCurrent = mContainedStringTableView->selectionModel()->currentIndex().isValid();
-    mGotoButton->setEnabled( isSelectable && hasCurrent );
+    const bool stringSelected = mContainedStringTableView->selectionModel()->currentIndex().isValid();
+    mGotoButton->setEnabled( canHighlightString && stringSelected );
 }
 
 
-
 void StringsExtractView::onGotoButtonClicked()
 {
     const QModelIndex index = mContainedStringTableView->selectionModel()->currentIndex();
@@ -192,11 +193,11 @@
 
 void StringsExtractView::onCopyButtonClicked()
 {
-    const QModelIndexList selectedIndexes = mContainedStringTableView->selectionModel()->selectedRows();
+    const QModelIndexList selectedRows = mContainedStringTableView->selectionModel()->selectedRows();
     const QList<ContainedString> *containedStringList = mTool->containedStringList();
 
     QString strings;
-    foreach( const QModelIndex &index, selectedIndexes )
+    foreach( const QModelIndex &index, selectedRows )
     {
         const int i = mSortFilterProxyModel->mapToSource(index).row();
         strings += ( containedStringList->at( i ).string() + '\n' ); //TODO: specific linefeed for platforms
@@ -211,14 +212,14 @@
     const bool hasSelection = selectionModel->hasSelection();
     mCopyButton->setEnabled( hasSelection );
 
-    const bool hasCurrent = selectionModel->currentIndex().isValid();
-    const bool isSelectable = mTool->isSelectable();
-    mGotoButton->setEnabled( isSelectable && hasCurrent );
+    const bool stringSelected = selectionModel->isSelected( selectionModel->currentIndex() );
+    const bool canHighlightString = mTool->canHighlightString();
+    mGotoButton->setEnabled( canHighlightString && stringSelected );
 }
 
 void StringsExtractView::onStringDoubleClicked( const QModelIndex &index )
 {
-    if( mTool->isSelectable() )
+    if( mTool->canHighlightString() )
         mTool->selectString( mSortFilterProxyModel->mapToSource(index).row() );
 }
 
--- trunk/KDE/kdeutils/okteta/program/oktetakakao/controllers/view/stringsextract/stringsextractview.h #826556:826557
@@ -54,7 +54,7 @@
   public Q_SLOTS: // tool
     void onStringsUptodateChanged( bool stringUptodate );
     void onApplyableChanged( bool isApplyable );
-    void onIsSelectableChanged( bool isSelectable );
+    void onCanHighlightStringChanged( bool isSelectable );
 
   private:
     StringsExtractTool *mTool;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic