Commit 7fa67bd4 authored by Olivier Trichet's avatar Olivier Trichet
Browse files

Properly insert element into the model by notifying the view of the change.

svn path=/trunk/KDE/kdeutils/ark/; revision=791549
parent ad72532a
......@@ -326,7 +326,7 @@ ArchiveDirNode* ArchiveModel::parentFor( const ArchiveEntry& entry )
ArchiveEntry e;
e[ FileName ] = parent->entry()[ FileName ].toString() + '/' + piece;
node = new ArchiveDirNode( parent, e );
parent->entries().append( node );
insertNode( node );
}
if ( !node->isDir() )
{
......@@ -334,7 +334,7 @@ ArchiveDirNode* ArchiveModel::parentFor( const ArchiveEntry& entry )
node = new ArchiveDirNode( parent, e );
//Maybe we have both a file and a directory of the same name
// We avoid removing previous entries unless necessary
parent->entries().append( node );
insertNode( node );
}
parent = static_cast<ArchiveDirNode*>( node );
}
......@@ -385,9 +385,6 @@ void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
/// 2. Find Parent Node, creating missing ArchiveDirNodes in the process
ArchiveDirNode *parent = parentFor( entry );
// TODO: Don't make everyone child of the root, obey the hierarchy
QModelIndex parentIndex = indexForNode( parent );
/// 3. Create an ArchiveNode
QString name = entry[ FileName ].toString().split( '/', QString::SkipEmptyParts ).last();
......@@ -398,8 +395,6 @@ void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
}
else
{
beginInsertRows( parentIndex, m_rootNode->entries().count(), m_rootNode->entries().count() );
if ( entry[ FileName ].toString().endsWith( '/' ) || ( entry.contains( IsDirectory ) && entry[ IsDirectory ].toBool() ) )
{
node = new ArchiveDirNode( parent, entry );
......@@ -408,12 +403,20 @@ void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
{
node = new ArchiveNode( parent, entry );
}
parent->entries().append( node );
endInsertRows();
insertNode( node );
}
}
void ArchiveModel::insertNode( ArchiveNode *node )
{
Q_ASSERT(node);
ArchiveDirNode *parent = node->parent();
Q_ASSERT(parent);
beginInsertRows( indexForNode( parent ), parent->entries().count(), parent->entries().count() );
parent->entries().append( node );
endInsertRows();
}
void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
{
delete m_archive;
......
......@@ -74,6 +74,11 @@ class ArchiveModel: public QAbstractItemModel
private:
ArchiveDirNode* parentFor( const ArchiveEntry& entry );
QModelIndex indexForNode( ArchiveNode *node );
/**
* Insert the node @p node into the model, ensuring all views are notified
* of the change.
*/
void insertNode( ArchiveNode *node );
Kerfuffle::Archive *m_archive;
ArchiveDirNode *m_rootNode;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment