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

List:       kde-commits
Subject:    extragear/multimedia/k3b
From:       Michal Malek <michalm () jabster ! pl>
Date:       2009-08-31 20:24:01
Message-ID: 1251750241.019254.12007.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1017895 by mmalek:

A bunch of small fixes making AudioProjectModel to behave better as a model. Right \
now it doesn't solve any particular bug, but can save us a headache in the future, \
especially when using AudioProjectModel with model wrappers (MetaItemModel, \
QAbstractProxyModel)

 M  +4 -0      libk3b/projects/audiocd/k3baudiodatasource.cpp  
 M  +2 -3      libk3b/projects/audiocd/k3baudiodoc.cpp  
 M  +3 -1      libk3b/projects/audiocd/k3baudiodoc.h  
 M  +15 -0     libk3b/projects/audiocd/k3baudiotrack.cpp  
 M  +5 -0      libk3b/projects/audiocd/k3baudiotrack.h  
 M  +31 -9     src/projects/k3baudioprojectmodel.cpp  
 M  +3 -1      src/projects/k3baudioprojectmodel.h  


--- trunk/extragear/multimedia/k3b/libk3b/projects/audiocd/k3baudiodatasource.cpp \
#1017894:1017895 @@ -85,6 +85,8 @@
 
     if( source == this )
         return;
+    
+    source->track()->emitAboutToAddSource( source->sourceIndex()+1 );
 
     // remove this from the list
     take();
@@ -114,6 +116,8 @@
 
     if( source == this )
         return;
+    
+    source->track()->emitAboutToAddSource( source->sourceIndex() );
 
     // remove this from the list
     take();
--- trunk/extragear/multimedia/k3b/libk3b/projects/audiocd/k3baudiodoc.cpp \
#1017894:1017895 @@ -349,7 +349,6 @@
             K3b::AudioTrack* newTrack = new K3b::AudioTrack( this );
             newTrack->addSource( source );
             newTrack->moveAfter( after );
-            emit trackAdded(newTrack);
 
             // we do not know the length of the source yet so we have to force the \
index value  if( track.index0() > 0 )
@@ -458,7 +457,8 @@
 
 void K3b::AudioDoc::addTrack( K3b::AudioTrack* track, int position )
 {
-    kDebug() << "(K3b::AudioDoc::addTrack( " << track << ", " << position << " )";
+    kDebug() << "(" << track << "," << position << ")";
+    
     track->m_parent = this;
     if( !m_firstTrack )
         m_firstTrack = m_lastTrack = track;
@@ -472,7 +472,6 @@
             track->moveAfter( m_lastTrack );  // just to be sure it's anywhere...
     }
 
-    emit trackAdded(track);
     emit changed();
 }
 
--- trunk/extragear/multimedia/k3b/libk3b/projects/audiocd/k3baudiodoc.h \
#1017894:1017895 @@ -190,10 +190,12 @@
         void trackRemoved( K3b::AudioTrack* );
 
         // signals for the model
+        void aboutToAddTrack( int position );
         void aboutToRemoveTrack( K3b::AudioTrack* );
+        void aboutToAddSource( K3b::AudioTrack*, int position );
         void sourceAdded( K3b::AudioTrack*, int position );
+        void aboutToRemoveSource( K3b::AudioTrack*, int position );
         void sourceRemoved( K3b::AudioTrack* );
-        void aboutToRemoveSource( K3b::AudioTrack*, int position );
 
     protected:
         /** reimplemented from Doc */
--- trunk/extragear/multimedia/k3b/libk3b/projects/audiocd/k3baudiotrack.cpp \
#1017894:1017895 @@ -293,6 +293,7 @@
         if( doc()->lastTrack() )
             moveAfter( doc()->lastTrack() );
         else {
+            emit doc()->aboutToAddTrack( 0 );
             doc()->setFirstTrack( take() );
             doc()->setLastTrack( this );
             emit doc()->trackAdded( this );
@@ -303,6 +304,8 @@
         return;
     }
     else {
+        emit track->doc()->aboutToAddTrack( track->trackNumber() );
+        
         // remove this from the list
         take();
 
@@ -344,6 +347,7 @@
         if( doc()->firstTrack() )
             moveAhead( doc()->firstTrack() );
         else {
+            emit doc()->aboutToAddTrack( 0 );
             doc()->setFirstTrack( take() );
             doc()->setLastTrack( this );
             emit doc()->trackAdded( this );
@@ -354,6 +358,8 @@
         return;
     }
     else {
+        emit track->doc()->aboutToAddTrack( track->trackNumber()-1 );
+        
         // remove this from the list
         take();
 
@@ -664,6 +670,7 @@
         setFirstSource( source->next() );
 }
 
+
 void K3b::AudioTrack::emitAboutToRemoveSource( AudioDataSource* source )
 {
     if ( doc() ) {
@@ -672,6 +679,14 @@
 }
 
 
+void K3b::AudioTrack::emitAboutToAddSource( int position )
+{
+    if ( doc() ) {
+        emit doc()->aboutToAddSource( this, position );
+    }
+}
+
+
 void K3b::AudioTrack::emitSourceAdded( AudioDataSource* source )
 {
     if ( doc() ) {
--- trunk/extragear/multimedia/k3b/libk3b/projects/audiocd/k3baudiotrack.h \
#1017894:1017895 @@ -192,6 +192,11 @@
          * Tells the audio doc one source is about to be removed
          */
         void emitAboutToRemoveSource( AudioDataSource* );
+        
+        /**
+         * Tells the audio doc one source is about to be added
+         */
+        void emitAboutToAddSource( int position );
 
         /**
          * Tells the audio doc one source was added to the list.
--- trunk/extragear/multimedia/k3b/src/projects/k3baudioprojectmodel.cpp \
#1017894:1017895 @@ -43,12 +43,14 @@
     K3b::AudioDoc* project;
 
     void _k_docChanged();
+    void _k_aboutToAddTrack( int position );
     void _k_trackAdded( K3b::AudioTrack* );
     void _k_aboutToRemoveTrack( K3b::AudioTrack* );
     void _k_trackRemoved();
+    void _k_aboutToAddSource( K3b::AudioTrack*, int );
     void _k_sourceAdded( K3b::AudioTrack*, int );
+    void _k_aboutToRemoveSource( K3b::AudioTrack*, int );
     void _k_sourceRemoved( K3b::AudioTrack* );
-    void _k_aboutToRemoveSource( K3b::AudioTrack*, int );
 
 private:
     AudioProjectModel* q;
@@ -61,12 +63,18 @@
 }
 
 
+void K3b::AudioProjectModel::Private::_k_aboutToAddTrack( int position )
+{
+    if (position >= 0) {
+        q->beginInsertRows( QModelIndex(), position, position );
+    }
+}
+
+
 void K3b::AudioProjectModel::Private::_k_trackAdded( K3b::AudioTrack* track )
 {
     int index = track->trackNumber() - 1;
-
     if (index >= 0) {
-        q->beginInsertRows( QModelIndex(), index, index );
         // do nothing
         q->endInsertRows();
     }
@@ -86,10 +94,15 @@
 }
 
 
-void K3b::AudioProjectModel::Private::_k_sourceAdded( K3b::AudioTrack* track, int \
position ) +void K3b::AudioProjectModel::Private::_k_aboutToAddSource( \
K3b::AudioTrack* track, int position )  {
     QModelIndex parent = q->indexForTrack( track );
     q->beginInsertRows( parent, position, position );
+}
+
+
+void K3b::AudioProjectModel::Private::_k_sourceAdded( K3b::AudioTrack*, int )
+{
     // do nothing
     q->endInsertRows();
 }
@@ -117,15 +130,19 @@
     connect( doc, SIGNAL( changed() ), this, SLOT( _k_docChanged() ) );
     connect( doc, SIGNAL( aboutToRemoveTrack( K3b::AudioTrack* ) ),
              this, SLOT( _k_aboutToRemoveTrack( K3b::AudioTrack* ) ) );
+    connect( doc, SIGNAL( aboutToAddTrack( int ) ),
+             this, SLOT( _k_aboutToAddTrack( int ) ) );
     connect( doc, SIGNAL( trackAdded( K3b::AudioTrack* ) ),
              this, SLOT( _k_trackAdded( K3b::AudioTrack* ) ) );
 
+    connect( doc, SIGNAL( aboutToAddSource( K3b::AudioTrack*, int ) ),
+             this, SLOT( _k_aboutToAddSource( K3b::AudioTrack*, int ) ) );
     connect( doc, SIGNAL( sourceAdded( K3b::AudioTrack*, int ) ),
              this, SLOT( _k_sourceAdded( K3b::AudioTrack*, int ) ) );
+    connect( doc, SIGNAL( aboutToRemoveSource( K3b::AudioTrack*, int ) ),
+             this, SLOT( _k_aboutToRemoveSource( K3b::AudioTrack*, int ) ) );
     connect( doc, SIGNAL( sourceRemoved( K3b::AudioTrack* ) ),
              this, SLOT( _k_sourceRemoved( K3b::AudioTrack* ) ) );
-    connect( doc, SIGNAL( aboutToRemoveSource( K3b::AudioTrack*, int ) ),
-             this, SLOT( _k_aboutToRemoveSource( K3b::AudioTrack*, int ) ) );
 }
 
 
@@ -333,8 +350,12 @@
 
 QModelIndex K3b::AudioProjectModel::index( int row, int column, const QModelIndex& \
parent ) const  {
+    if ( !hasIndex( row, column, parent ) ) {
+        return QModelIndex();
+    }
+    
     // source
-    if ( parent.isValid() ) {
+    else if ( parent.isValid() && parent.column() == 0 ) {
         if ( K3b::AudioTrack* track = trackForIndex( parent ) ) {
             if ( K3b::AudioDataSource* source = track->getSource( row ) ) {
                 return createIndex( row, column, source );
@@ -343,7 +364,7 @@
     }
 
     // track
-    else if ( row >= 0 && row < d->project->numOfTracks() ) {
+    else if ( !parent.isValid() && row >= 0 && row < d->project->numOfTracks() ) {
         return createIndex( row, column, d->project->getTrack( row+1 ) );
     }
 
@@ -366,7 +387,8 @@
 int K3b::AudioProjectModel::rowCount( const QModelIndex& parent ) const
 {
     if ( parent.isValid() ) {
-        if ( K3b::AudioTrack* track = trackForIndex( parent ) ) {
+        K3b::AudioTrack* track = trackForIndex( parent );
+        if ( track != 0 && parent.column() == 0 ) {
             // first level
             return track->numberSources();
         }
--- trunk/extragear/multimedia/k3b/src/projects/k3baudioprojectmodel.h \
#1017894:1017895 @@ -73,12 +73,14 @@
         Private* const d;
 
         Q_PRIVATE_SLOT( d, void _k_docChanged() )
+        Q_PRIVATE_SLOT( d, void _k_aboutToAddTrack( int position ) )
         Q_PRIVATE_SLOT( d, void _k_trackAdded( K3b::AudioTrack* ) )
         Q_PRIVATE_SLOT( d, void _k_aboutToRemoveTrack( K3b::AudioTrack* ) )
         Q_PRIVATE_SLOT( d, void _k_trackRemoved() )
+        Q_PRIVATE_SLOT( d, void _k_aboutToAddSource( K3b::AudioTrack*, int ) )
         Q_PRIVATE_SLOT( d, void _k_sourceAdded( K3b::AudioTrack*, int ) )
+        Q_PRIVATE_SLOT( d, void _k_aboutToRemoveSource( K3b::AudioTrack*, int ) )
         Q_PRIVATE_SLOT( d, void _k_sourceRemoved( K3b::AudioTrack* ) )
-        Q_PRIVATE_SLOT( d, void _k_aboutToRemoveSource( K3b::AudioTrack*, int ) )
     };
 }
 


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

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