Commit caf80ca7 authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Implement sorting on filenames

svn path=/trunk/KDE/kdeutils/ark/; revision=948149
parent f3dcde88
......@@ -54,6 +54,11 @@ class ArchiveNode
virtual ~ArchiveNode() {}
static bool compare(const ArchiveNode* a, const ArchiveNode* b)
{
return (a->m_name < b->m_name);
}
ArchiveEntry entry() const { return m_entry; }
void setEntry( const ArchiveEntry & entry )
{
......@@ -140,6 +145,27 @@ class ArchiveDirNode: public ArchiveNode
return 0;
}
void returnDirNodes(QList<ArchiveDirNode*> *store)
{
foreach( ArchiveNode *node, m_entries )
{
if ( node->isDir() )
{
store->append(static_cast<ArchiveDirNode*>(node));
static_cast<ArchiveDirNode*>(node)->returnDirNodes(store);
}
}
}
void sort()
{
QList<ArchiveDirNode*> dirNodes;
returnDirNodes(&dirNodes);
foreach(ArchiveDirNode* dir, dirNodes) {
qSort(dir->entries().begin(), dir->entries().end(),ArchiveNode::compare );
}
}
void clear()
{
qDeleteAll( m_entries );
......@@ -404,6 +430,13 @@ int ArchiveModel::columnCount( const QModelIndex &parent ) const
}
}
void ArchiveModel::sort ( int column, Qt::SortOrder order )
{
kDebug(1601);
m_rootNode->sort();
reset();
}
Qt::DropActions ArchiveModel::supportedDropActions () const
{
return Qt::CopyAction | Qt::MoveAction;
......
......@@ -48,6 +48,8 @@ class ArchiveModel: public QAbstractItemModel
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
virtual void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder );
//drag and drop related
virtual Qt::DropActions supportedDropActions () const;
virtual QStringList mimeTypes () const;
......
......@@ -42,6 +42,7 @@ void ArchiveView::setModel(QAbstractItemModel *model)
setAlternatingRowColors( true );
setAnimated( true );
setAllColumnsShowFocus( true );
setSortingEnabled(true);
header()->setResizeMode(QHeaderView::ResizeToContents);
......
......@@ -168,6 +168,8 @@ void Part::setupView()
{
m_view->setModel( m_model );
m_view->setSortingEnabled(true);
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( updateActions() ) );
connect( m_view->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
......
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