Commit cecd1dfc authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Introduced a SortedDirModel, so that it will be possible to implement sorting

by date, size...

svn path=/trunk/playground/graphics/gwenview/; revision=633038
parent 98d01bda
/*
Gwenview: an image viewer
Copyright 2007 Aurlien Gteau
Copyright 2007 Aurélien Gâteau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <kactioncollection.h>
#include <kaction.h>
#include <kdirlister.h>
#include <kdirmodel.h>
#include <kfileitem.h>
#include <klocale.h>
#include <kurl.h>
......@@ -42,6 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Local
#include <lib/thumbnailview.h>
#include <lib/mimetypeutils.h>
#include <lib/sorteddirmodel.h>
namespace Gwenview {
......@@ -61,7 +61,7 @@ struct MainWindow::Private {
QAction* mImageOnlyAction;
QAction* mGoUpAction;
KDirModel* mDirModel;
SortedDirModel* mDirModel;
void setupWidgets() {
QSplitter* centralSplitter = new QSplitter(Qt::Horizontal, mWindow);
......@@ -148,7 +148,7 @@ MainWindow::MainWindow()
d(new MainWindow::Private)
{
d->mWindow = this;
d->mDirModel = new KDirModel(this);
d->mDirModel = new SortedDirModel(this);
d->setupWidgets();
d->setupActions();
QTimer::singleShot(0, this, SLOT(initDirModel()) );
......
set(gwenviewlib_SRCS
thumbnailview.cpp
archiveutils.cpp
mimetypeutils.cpp
sorteddirmodel.cpp
thumbnailview.cpp
)
kde4_automoc(${gwenviewlib_SRCS})
......
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "sorteddirmodel.h"
// KDE
#include <kdirmodel.h>
namespace Gwenview {
struct SortedDirModel::Private {
KDirModel* mSourceModel;
};
SortedDirModel::SortedDirModel(QObject* parent)
: QSortFilterProxyModel(parent)
, d(new SortedDirModel::Private)
{
d->mSourceModel = new KDirModel(this);
setSourceModel(d->mSourceModel);
setDynamicSortFilter(true);
setSortRole(Qt::DisplayRole);
setSortCaseSensitivity(Qt::CaseInsensitive);
sort(KDirModel::Name);
}
KDirLister* SortedDirModel::dirLister() {
return d->mSourceModel->dirLister();
}
KFileItem* SortedDirModel::itemForIndex(const QModelIndex& index) const {
if (!index.isValid()) {
return 0;
}
QModelIndex sourceIndex = mapToSource(index);
return d->mSourceModel->itemForIndex(sourceIndex);
}
} //namespace
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SORTEDDIRMODEL_H
#define SORTEDDIRMODEL_H
#include <memory>
#include <QSortFilterProxyModel>
class KDirLister;
class KFileItem;
namespace Gwenview {
class SortedDirModel : public QSortFilterProxyModel {
public:
SortedDirModel(QObject* parent);
KDirLister* dirLister();
KFileItem* itemForIndex(const QModelIndex& index) const;
private:
struct Private;
std::auto_ptr<Private> d;
};
} // namespace
#endif /* SORTEDDIRMODEL_H */
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