diff --git a/qmlUiKirigami/AlbumDelegate.qml b/qmlUiKirigami/AlbumDelegate.qml --- a/qmlUiKirigami/AlbumDelegate.qml +++ b/qmlUiKirigami/AlbumDelegate.qml @@ -88,7 +88,7 @@ gridView.model.clearSelections() switch( model.itemType) { case Koko.Types.Album: { - imageListModel.imageList = model.files + imageListModel.query = imageListModel.queryForIndex( model.sourceIndex) sortedListModel.sourceModel = imageListModel collectionSelected( sortedListModel, model.display) break; diff --git a/qmlUiKirigami/AlbumView.qml b/qmlUiKirigami/AlbumView.qml --- a/qmlUiKirigami/AlbumView.qml +++ b/qmlUiKirigami/AlbumView.qml @@ -89,9 +89,6 @@ Koko.SortModel { id: sortedListModel } - Koko.ImageListModel { - id: imageListModel - } Koko.ImageFolderModel { id: imageFolderModel } diff --git a/qmlUiKirigami/main.qml b/qmlUiKirigami/main.qml --- a/qmlUiKirigami/main.qml +++ b/qmlUiKirigami/main.qml @@ -53,34 +53,43 @@ switch( value){ case "Countries": { albumView.model = imageLocationModelCountry; + imageListModel.locationGroup = Koko.Types.Country; break; } case "States": { albumView.model = imageLocationModelState; + imageListModel.locationGroup = Koko.Types.State; break; } case "Cities": { albumView.model = imageLocationModelCity; + imageListModel.locationGroup = Koko.Types.City; break; } case "Years": { albumView.model = imageTimeModelYear; + imageListModel.timeGroup = Koko.Types.Year; break; } case "Months": { albumView.model = imageTimeModelMonth; + imageListModel.timeGroup = Koko.Types.Month; break; } case "Weeks": { - albumView.model = imageTimeModelWeek; + albumView.model = imageTimeModelWeek; + imageListModel.timeGroup = Koko.Types.Week; break; } case "Days": { albumView.model = imageTimeModelDay; + imageListModel.timeGroup = Koko.Types.Day; break; } case "Folders": { albumView.model = imageFolderModel; + imageListModel.locationGroup = -1; + imageListModel.timeGroup = -1; break; } } @@ -147,6 +156,10 @@ } } + Koko.ImageListModel { + id: imageListModel + } + ImageViewer { id: imageViewer //go on top of the overlay drawer diff --git a/src/imagelistmodel.h b/src/imagelistmodel.h --- a/src/imagelistmodel.h +++ b/src/imagelistmodel.h @@ -22,14 +22,16 @@ #include +#include "types.h" + class ImageListModel : public QAbstractListModel { Q_OBJECT - /* - * imageList property is used to store the images of a particular collection - */ - Q_PROPERTY(QStringList imageList READ imageList WRITE setImageList NOTIFY imageListChanged) + Q_PROPERTY(Types::LocationGroup locationGroup READ locationGroup WRITE setLocationGroup NOTIFY locationGroupChanged) + Q_PROPERTY(Types::TimeGroup timeGroup READ timeGroup WRITE setTimeGroup NOTIFY timeGroupChanged) + Q_PROPERTY(Types::QueryType queryType READ queryType WRITE setQueryType) + Q_PROPERTY(QByteArray query READ query WRITE setQuery NOTIFY queryChanged) public: explicit ImageListModel(QObject* parent = 0); @@ -39,14 +41,39 @@ virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; - QStringList imageList() const; - void setImageList(QStringList images); + Types::LocationGroup locationGroup() const; + void setLocationGroup(const Types::LocationGroup &group); + + Types::TimeGroup timeGroup() const; + void setTimeGroup(const Types::TimeGroup &group); + + Types::QueryType queryType() const; + void setQueryType( const Types::QueryType &type); + + QByteArray query() const; + void setQuery(const QByteArray &statement); + + Q_INVOKABLE QByteArray queryForIndex(const QModelIndex &index); + + void slotLocationGroupChanged(); + void slotTimeGroupChanged(); + void slotResetModel(); Q_SIGNALS: void imageListChanged(); + void locationGroupChanged(); + void timeGroupChanged(); + void queryChanged(); private: QStringList m_images; + Types::LocationGroup m_locationGroup; + Types::TimeGroup m_timeGroup; + Types::QueryType m_queryType; + QByteArray m_query; + + QList< QPair > m_times; + QList< QPair > m_locations; }; #endif diff --git a/src/imagelistmodel.cpp b/src/imagelistmodel.cpp --- a/src/imagelistmodel.cpp +++ b/src/imagelistmodel.cpp @@ -18,15 +18,24 @@ */ #include "imagelistmodel.h" -#include "types.h" #include "roles.h" +#include "imagestorage.h" #include #include ImageListModel::ImageListModel(QObject* parent) : QAbstractListModel(parent) { + connect(this, &ImageListModel::locationGroupChanged, + this, &ImageListModel::slotLocationGroupChanged); + connect(this, &ImageListModel::timeGroupChanged, + this, &ImageListModel::slotTimeGroupChanged); + connect(this, &ImageListModel::queryChanged, + this, &ImageListModel::slotResetModel); + + connect(ImageStorage::instance(), &ImageStorage::storageModified, + this, &ImageListModel::slotResetModel); } ImageListModel::~ImageListModel() @@ -37,7 +46,6 @@ { QHash hash = QAbstractListModel::roleNames(); hash.insert( Roles::ImageUrlRole, "imageurl"); - hash.insert( Roles::MimeTypeRole, "mimeType"); hash.insert( Roles::ItemTypeRole, "itemType"); return hash; @@ -50,8 +58,6 @@ } int indexValue = index.row(); - QMimeDatabase db; - QMimeType type = db.mimeTypeForFile(m_images.at(indexValue)); switch( role) { case Qt::DisplayRole: @@ -61,9 +67,6 @@ case Roles::ImageUrlRole: return m_images.at(indexValue); - case Roles::MimeTypeRole: - return type.name(); - case Roles::ItemTypeRole: return Types::Image; @@ -78,15 +81,83 @@ return m_images.size(); } -QStringList ImageListModel::imageList() const +void ImageListModel::slotLocationGroupChanged() +{ + if( m_locationGroup != -1) { + m_locations = ImageStorage::instance()->locations( static_cast(m_locationGroup)); + m_queryType = Types::LocationQuery; + } +} + +void ImageListModel::slotTimeGroupChanged() +{ + if( m_timeGroup != -1) { + m_times = ImageStorage::instance()->timeTypes( static_cast(m_timeGroup)); + m_queryType = Types::TimeQuery; + } +} + +void ImageListModel::slotResetModel() +{ + beginResetModel(); + if(m_queryType == Types::LocationQuery) { + m_images = ImageStorage::instance()->imagesForLocation( m_query, static_cast(m_locationGroup)); + } else if (m_queryType == Types::TimeQuery) { + m_images = ImageStorage::instance()->imagesForTime( m_query, static_cast(m_timeGroup)); + } + endResetModel(); +} + +Types::LocationGroup ImageListModel::locationGroup() const { - return m_images; + return m_locationGroup; } -void ImageListModel::setImageList(QStringList images) +void ImageListModel::setLocationGroup(const Types::LocationGroup &group) { - m_images = images; - emit imageListChanged(); + m_locationGroup = group; + emit locationGroupChanged(); +} + +Types::TimeGroup ImageListModel::timeGroup() const +{ + return m_timeGroup; +} + +void ImageListModel::setTimeGroup(const Types::TimeGroup &group) +{ + m_timeGroup = group; + emit timeGroupChanged(); +} + +Types::QueryType ImageListModel::queryType() const +{ + return m_queryType; +} + +void ImageListModel::setQueryType(const Types::QueryType& type) +{ + m_queryType = type; +} + +QByteArray ImageListModel::query() const +{ + return m_query; +} +void ImageListModel::setQuery(const QByteArray &statement) +{ + m_query = statement; + emit queryChanged(); +} + +QByteArray ImageListModel::queryForIndex(const QModelIndex &index) +{ + if(m_queryType == Types::LocationQuery) { + return m_locations.at( index.row()).first; + } else if( m_queryType == Types::TimeQuery) { + return m_times.at( index.row()).first; + } + return QByteArray(); } #include "moc_imagelistmodel.cpp" diff --git a/src/roles.h b/src/roles.h --- a/src/roles.h +++ b/src/roles.h @@ -35,7 +35,8 @@ FilesRole, FileCountRole, DateRole, - SelectedRole + SelectedRole, + SourceIndex }; }; diff --git a/src/sortmodel.cpp b/src/sortmodel.cpp --- a/src/sortmodel.cpp +++ b/src/sortmodel.cpp @@ -112,6 +112,7 @@ QHash hash = sourceModel()->roleNames(); hash.insert( Roles::SelectedRole, "selected"); hash.insert( Roles::Thumbnail, "thumbnail"); + hash.insert( Roles::SourceIndex, "sourceIndex"); return hash; } @@ -142,6 +143,9 @@ const_cast(this)->m_filesToPreview[item.url()] = QPersistentModelIndex(index); } + case Roles::SourceIndex: { + return mapToSource(index); + } } return QSortFilterProxyModel::data(index, role); diff --git a/src/types.h b/src/types.h --- a/src/types.h +++ b/src/types.h @@ -26,6 +26,7 @@ Q_ENUMS(ItemTypes) Q_ENUMS(TimeGroup) Q_ENUMS(LocationGroup) + Q_ENUMS(QueryType) public: Types(QObject* parent); ~Types(); @@ -45,6 +46,11 @@ City }; + enum QueryType { + LocationQuery = 10, + TimeQuery + }; + }; #endif