-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimagelistmodel.cpp
43 lines (37 loc) · 1.14 KB
/
imagelistmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "imagelistmodel.h"
#include <QDebug>
#include <QDir>
ImageListModel::ImageListModel(QObject* parent)
: QAbstractTableModel(parent)
{
imageNameFilter << "*.png"
<< "*.jpg"
<< "*.gif";
}
bool ImageListModel::loadDirectoryImageList(const QString& fullPath)
{
qInfo() << "Loading Image List From " << fullPath << "started";
QDir directory{ fullPath };
beginResetModel();
imageFileInfoList = directory.entryInfoList(imageNameFilter, QDir::Files, QDir::Name);
qInfo() << "Loading Image List From " << fullPath << "finished: " << imageFileInfoList.size() << "images";
endResetModel();
return true;
}
int ImageListModel::rowCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : imageFileInfoList.size();
}
int ImageListModel::columnCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : 1;
}
QVariant ImageListModel::data(const QModelIndex& index, int role) const
{
if (index.isValid()) {
if (role == Qt::DisplayRole) {
return imageFileInfoList[index.row()].absoluteFilePath();
}
}
return QVariant();
}