Permalink
Browse files

ThumbnailItemDelegate: Use file path instead of index for thumbnail c…

…ache
  • Loading branch information...
1 parent 133094a commit 978edcc5e19a37eb4fd3896a6e882445ece5fd7a @nikola-kocic committed Dec 20, 2011
View
@@ -37,17 +37,17 @@ QStringList FileInfo::getFiltersImage()
return m_filters_image;
}
-bool FileInfo::isZip() const
+bool FileInfo::isArchive() const
{
- return !zipPath.isEmpty();
+ return !container.isDir();
}
bool FileInfo::fileExists() const
{
bool exists = false;
if (isValidContainer())
{
- if (isZip())
+ if (isArchive())
{
exists = !zipImageFileName.isEmpty();
}
@@ -65,18 +65,16 @@ bool FileInfo::fileExists() const
bool FileInfo::isValidContainer() const
{
- bool valid = false;
- valid = container.exists();
+ bool valid = container.exists();
#ifdef DEBUG_FILE_INFO
qDebug() << QDateTime::currentDateTime() << "FileInfo::isValidContainer()" << container.canonicalFilePath() << "valid" << valid;
#endif
-
return valid;
}
QString FileInfo::getFilePath() const
{
- if (isZip())
+ if (isArchive())
{
return container.canonicalFilePath() + "/" + zipImagePath();
}
@@ -97,7 +95,7 @@ QString FileInfo::zipImagePath() const
QString FileInfo::getImageFileName() const
{
- if (isZip())
+ if (isArchive())
{
return zipImageFileName;
}
@@ -131,7 +129,7 @@ FileInfo FileInfo::fromPath(const QString &path)
#endif
info.container = fi.canonicalFilePath();
}
- else if (isArchive(fi))
+ else if (isArchiveFile(fi))
{
#ifdef DEBUG_FILE_INFO
qDebug() << QDateTime::currentDateTime() << "FileInfo::fromPath" << "isArchive(fi)";
View
@@ -11,7 +11,7 @@ class FileInfo
FileInfo();
static FileInfo fromPath(const QString &);
- bool isZip() const;
+ bool isArchive() const;
bool fileExists() const;
bool isValidContainer() const;
View
@@ -5,7 +5,7 @@
bool checkFileExtension(const QFileInfo &info)
{
- if (isArchive(info) || info.isDir() || isImage(info))
+ if (isArchiveFile(info) || info.isDir() || isImageFile(info))
{
return true;
}
@@ -15,12 +15,12 @@ bool checkFileExtension(const QFileInfo &info)
}
}
-bool isArchive(const QFileInfo &fi)
+bool isArchiveFile(const QFileInfo &fi)
{
return FileInfo::getFiltersArchive().contains(fi.suffix().toLower());
}
-bool isImage(const QFileInfo &fi)
+bool isImageFile(const QFileInfo &fi)
{
return FileInfo::getFiltersImage().contains(fi.suffix().toLower());
}
View
@@ -11,14 +11,14 @@ namespace LockMode
enum Mode { None, Autofit, FitWidth, FitHeight, Zoom };
}
-const int ROLE_TYPE = Qt::UserRole + 1;
+const int ROLE_TYPE = Qt::UserRole + 1000;
const int TYPE_ARCHIVE_DIR = 1004;
const int TYPE_ARCHIVE_FILE = 1005;
-bool isImage(const QFileInfo &fi);
-bool isArchive(const QFileInfo &fi);
+bool isImageFile(const QFileInfo &fi);
+bool isArchiveFile(const QFileInfo &fi);
bool checkFileExtension(const QFileInfo &fi);
static inline bool FuzzyCompare(double p1, double p2)
View
@@ -20,12 +20,12 @@ SOURCES += \
view_files.cpp \
teximg.cpp \
picture_loader.cpp \
- model_files.cpp \
helper.cpp \
fileinfo.cpp \
view_files_list.cpp \
thumbnailitemdelegate.cpp \
- view_files_tree.cpp
+ view_files_tree.cpp \
+ model_archive.cpp
HEADERS += \
quazip/zip.h \
@@ -50,10 +50,10 @@ HEADERS += \
tiledim.h \
teximg.h \
picture_loader.h \
- model_files.h \
helper.h \
fileinfo.h \
- thumbnailitemdelegate.h
+ thumbnailitemdelegate.h \
+ model_archive.h
RESOURCES += \
kiv.qrc
View
@@ -749,7 +749,7 @@ void MainWindow::on_lineEditPath_editingFinished()
bool valid = false;
if (info.isValidContainer())
{
- if (info.isZip())
+ if (info.isArchive())
{
valid = true;
}
@@ -887,7 +887,7 @@ bool MainWindow::saveAs()
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
- if (info.isZip())
+ if (info.isArchive())
{
JlCompress::extractFile(info.container.canonicalFilePath(), info.zipImagePath(), fileName);
}
View
@@ -4,7 +4,7 @@
#include "view_files.h"
#include "picture_loader.h"
#include "pictureitem.h"
-#include "model_files.h"
+#include "model_archive.h"
#include "view_archive_dirs.h"
#include <QFileSystemModel>
@@ -1,4 +1,4 @@
-#include "model_files.h"
+#include "model_archive.h"
#include "helper.h"
#include "settings.h"
#include "quazip/quazip.h"
@@ -7,13 +7,14 @@
#include <QFile>
#include <QDir>
#include <QtGui/QStyle>
+#include <QFileSystemModel>
//#define DEBUG_MODEL_FILES
#ifdef DEBUG_MODEL_FILES
#include <QDebug>
#endif
-FilesModel::FilesModel(QObject *parent)
+ArchiveFilesModel::ArchiveFilesModel(QObject *parent)
: QStandardItemModel(parent)
{
m_icon_dir = QApplication::style()->standardIcon(QStyle::SP_DirIcon);
@@ -50,15 +51,14 @@ QString bytesToSize(int bytes, int precision)
else if (bytes >= terabyte)
{
return QString::number(((float)bytes / terabyte), 'f', precision) + " TiB";
-
}
else
{
return QString::number(bytes) + " B";
}
}
-void FilesModel::setPath(const FileInfo &info)
+void ArchiveFilesModel::setPath(const FileInfo &info)
{
#ifdef DEBUG_MODEL_FILES
qDebug() << QDateTime::currentDateTime() << "FilesModel::setPath" << path.getFilePath();
@@ -99,20 +99,25 @@ void FilesModel::setPath(const FileInfo &info)
{
node = root;
QStringList file_path_parts = archive_files.at(i).split('/');
+ QString folderPath = info.container.canonicalFilePath() + "/";
for (int j = 0; j < file_path_parts.size(); ++j)
{
if (file_path_parts.at(j).size() > 0)
{
+ folderPath.append(file_path_parts.at(j) + "/");
if (j < file_path_parts.size() - 1)
{
node = AddNode(node, file_path_parts.at(j), TYPE_ARCHIVE_DIR);
+ node->setData(folderPath, QFileSystemModel::FilePathRole);
}
else
{
QFileInfo fi(archive_files.at(i));
- if (isImage(fi))
+ if (isImageFile(fi))
{
+ QString nodeFilePath = info.container.canonicalFilePath() + "/" + archive_files.at(i);
node = AddNode(node, file_path_parts.at(j), TYPE_ARCHIVE_FILE);
+ node->setData(nodeFilePath, QFileSystemModel::FilePathRole);
}
}
}
@@ -123,13 +128,13 @@ void FilesModel::setPath(const FileInfo &info)
}
-QStandardItem* FilesModel::AddNode(QStandardItem *node, const QString &name, int type)
+QStandardItem* ArchiveFilesModel::AddNode(QStandardItem *parent, const QString &name, int type)
{
- for (int i = 0; i < node->rowCount(); ++i)
+ for (int i = 0; i < parent->rowCount(); ++i)
{
- if (node->child(i)->text() == name)
+ if (parent->child(i)->text() == name)
{
- return node->child(i);
+ return parent->child(i);
}
}
@@ -139,18 +144,18 @@ QStandardItem* FilesModel::AddNode(QStandardItem *node, const QString &name, int
if (type == TYPE_ARCHIVE_DIR)
{
ntvi->setIcon(m_icon_dir);
- indexToInsertByName(node, name);
- node->insertRow(indexToInsertByName(node, name), ntvi);
+ indexToInsertByName(parent, name);
+ parent->insertRow(indexToInsertByName(parent, name), ntvi);
}
else
{
ntvi->setIcon(m_icon_file);
- node->appendRow(ntvi);
+ parent->appendRow(ntvi);
}
return ntvi;
}
-int FilesModel::indexToInsertByName(QStandardItem *parent, const QString &name)
+int ArchiveFilesModel::indexToInsertByName(QStandardItem *parent, const QString &name)
{
int lastFolderIndex = 0;
for (int i = 0; i < parent->rowCount(); ++i)
@@ -169,7 +174,7 @@ int FilesModel::indexToInsertByName(QStandardItem *parent, const QString &name)
return lastFolderIndex;
}
-QModelIndex FilesModel::getDirectory(const QString &path)
+QModelIndex ArchiveFilesModel::getDirectory(const QString &path)
{
QModelIndex cri = invisibleRootItem()->child(0)->index();
@@ -186,7 +191,7 @@ QModelIndex FilesModel::getDirectory(const QString &path)
return cri;
}
-QModelIndex FilesModel::findIndexChild(const QString &text, const QModelIndex &root)
+QModelIndex ArchiveFilesModel::findIndexChild(const QString &text, const QModelIndex &root)
{
if (!root.isValid()) return QModelIndex();
for (int i = 0; root.child(i, 0).isValid(); ++i)
@@ -198,15 +203,3 @@ QModelIndex FilesModel::findIndexChild(const QString &text, const QModelIndex &r
}
return QModelIndex();
}
-
-QModelIndex FilesModel::findRootIndexChild(const QString &text)
-{
- for (int i = 0; i < this->rowCount(); ++i)
- {
- if (index(i, 0).data() == text)
- {
- return index(i, 0);
- }
- }
- return QModelIndex();
-}
@@ -6,19 +6,19 @@
#include <QStandardItemModel>
#include <QFileIconProvider>
-class FilesModel : public QStandardItemModel
+class ArchiveFilesModel : public QStandardItemModel
{
Q_OBJECT
public:
- FilesModel(QObject *parent = 0);
+ ArchiveFilesModel(QObject *parent = 0);
void setPath(const FileInfo &info);
QModelIndex getDirectory(const QString &path);
QModelIndex findIndexChild(const QString &text, const QModelIndex &root = QModelIndex());
QModelIndex findRootIndexChild(const QString &text);
private:
- QStandardItem* AddNode(QStandardItem *node, const QString &name, int type);
+ QStandardItem* AddNode(QStandardItem *parent, const QString &name, int type);
int indexToInsertByName(QStandardItem *parent, const QString &name);
QIcon m_icon_dir;
QIcon m_icon_file;
View
@@ -24,14 +24,15 @@ QImage PictureLoader::getImage(const FileInfo &info)
{
return QImage(0,0);
}
- else if (info.isZip())
+ else if (info.isArchive())
{
return PictureLoader::getImageFromZip(ThumbnailInfo(info, QSize(0, 0)));
}
else
{
return PictureLoader::getImageFromFile(ThumbnailInfo(info, QSize(0, 0)));
}
+ return QImage(0,0);
}
QImage PictureLoader::getThumbnail(const ThumbnailInfo &thumb_info)
@@ -43,14 +44,15 @@ QImage PictureLoader::getThumbnail(const ThumbnailInfo &thumb_info)
{
return QImage(0,0);
}
- else if (thumb_info.info.isZip())
+ else if (thumb_info.info.isArchive())
{
return PictureLoader::styleThumbnail(PictureLoader::getImageFromZip(thumb_info), thumb_info);
}
else
{
return PictureLoader::styleThumbnail(PictureLoader::getImageFromFile(thumb_info), thumb_info);
}
+ return QImage(0,0);
}
QImage PictureLoader::styleThumbnail(const QImage &img, const ThumbnailInfo &thumb_info)
Oops, something went wrong.

0 comments on commit 978edcc

Please sign in to comment.