| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#pragma once |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <QAbstractListModel> |
| 20 |
#include <QUrl> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "dragdropimplementations.h" |
| 25 |
#include "abstractitemdragdrophandler.h" |
| 26 |
#include "showfotoiteminfo.h" |
| 27 |
|
| 28 |
using namespace Digikam; |
| 29 |
|
| 30 |
namespace ShowFoto |
| 31 |
{ |
| 32 |
|
| 33 |
typedef QPair<int, int> IntPair; |
| 34 |
|
| 35 |
class ShowfotoItemModel : public QAbstractListModel, |
| 36 |
public DragDropModelImplementation |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
|
| 40 |
public: |
| 41 |
|
| 42 |
enum ShowfotoItemModelRoles |
| 43 |
{ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ShowfotoItemModelPointerRole = Qt::UserRole, |
| 48 |
ShowfotoItemModelInternalId = Qt::UserRole + 1, |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
ThumbnailRole = Qt::UserRole + 2, |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
ExtraDataRole = Qt::UserRole + 3, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
ExtraDataDuplicateCount = Qt::UserRole + 6, |
| 65 |
|
| 66 |
FilterModelRoles = Qt::UserRole + 100 |
| 67 |
}; |
| 68 |
|
| 69 |
public: |
| 70 |
|
| 71 |
explicit ShowfotoItemModel(QObject* const parent); |
| 72 |
~ShowfotoItemModel() override; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
void setKeepsFileUrlCache(bool keepCache); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
ShowfotoItemInfo showfotoItemInfo(const QModelIndex& index) const; |
| 86 |
ShowfotoItemInfo& showfotoItemInfoRef(const QModelIndex& index) const; |
| 87 |
qlonglong showfotoItemId(const QModelIndex& index) const; |
| 88 |
ShowfotoItemInfoList showfotoItemInfos(const QList<QModelIndex>& indexes) const; |
| 89 |
QList<qlonglong> showfotoItemIds(const QList<QModelIndex>& indexes) const; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
ShowfotoItemInfo showfotoItemInfo(int row) const; |
| 97 |
ShowfotoItemInfo& showfotoItemInfoRef(int row) const; |
| 98 |
qlonglong showfotoItemId(int row) const; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
QModelIndex indexForShowfotoItemInfo(const ShowfotoItemInfo& info) const; |
| 104 |
QList<QModelIndex> indexesForShowfotoItemInfo(const ShowfotoItemInfo& info) const; |
| 105 |
QModelIndex indexForShowfotoItemId(qlonglong id) const; |
| 106 |
QList<QModelIndex> indexesForShowfotoItemId(qlonglong id) const; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
QModelIndex indexForUrl(const QUrl& fileUrl) const; |
| 114 |
QList<QModelIndex> indexesForUrl(const QUrl& fileUrl) const; |
| 115 |
ShowfotoItemInfo showfotoItemInfo(const QUrl& fileUrl) const; |
| 116 |
QList<ShowfotoItemInfo> showfotoItemInfos(const QUrl& fileUrl) const; |
| 117 |
|
| 118 |
void addShowfotoItemInfo(const ShowfotoItemInfo& info); |
| 119 |
void addShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
void clearShowfotoItemInfos(); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
void addShowfotoItemInfoSynchronously(const ShowfotoItemInfo& info); |
| 133 |
void addShowfotoItemInfosSynchronously(const QList<ShowfotoItemInfo>& infos); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
void setShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos); |
| 139 |
|
| 140 |
QList<ShowfotoItemInfo> showfotoItemInfos() const; |
| 141 |
QList<qlonglong> showfotoItemIds() const; |
| 142 |
QList<ShowfotoItemInfo> uniqueShowfotoItemInfos() const; |
| 143 |
|
| 144 |
bool hasImage(qlonglong id) const; |
| 145 |
bool hasImage(const ShowfotoItemInfo& info) const; |
| 146 |
|
| 147 |
bool isEmpty() const; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void removeIndex(const QModelIndex& index); |
| 153 |
void removeIndexs(const QList<QModelIndex>& indexes); |
| 154 |
void removeShowfotoItemInfo(const ShowfotoItemInfo& info); |
| 155 |
void removeShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos); |
| 156 |
|
| 157 |
int numberOfIndexesForShowfotoItemInfo(const ShowfotoItemInfo& info) const; |
| 158 |
int numberOfIndexesForShowfotoItemId(qlonglong id) const; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
static ShowfotoItemInfo retrieveShowfotoItemInfo(const QModelIndex& index); |
| 165 |
static qlonglong retrieveShowfotoItemId(const QModelIndex& index); |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
int rowCount(const QModelIndex& parent) const override; |
| 171 |
QVariant data(const QModelIndex& index, int role) const override; |
| 172 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const override; |
| 173 |
Qt::ItemFlags flags(const QModelIndex& index) const override; |
| 174 |
QModelIndex index(int row, int column, const QModelIndex& parent) const override; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
DECLARE_MODEL_DRAG_DROP_METHODS |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
void setSendRemovalSignals(bool send); |
| 186 |
|
| 187 |
Q_SIGNALS: |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
void itemInfosAboutToBeAdded(const QList<ShowfotoItemInfo>& infos); |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void itemInfosAdded(const QList<ShowfotoItemInfo>& infos); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
void itemInfosAboutToBeRemoved(const QList<ShowfotoItemInfo>& infos); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
void itemInfosRemoved(const QList<ShowfotoItemInfo>& infos); |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
void preprocess(const QList<ShowfotoItemInfo>& infos); |
| 221 |
void processAdded(const QList<ShowfotoItemInfo>& infos); |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
void readyForIncrementalRefresh(); |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
void allRefreshingFinished(); |
| 235 |
|
| 236 |
public Q_SLOTS: |
| 237 |
|
| 238 |
void reAddShowfotoItemInfos(const ShowfotoItemInfoList& infos); |
| 239 |
void reAddingFinished(); |
| 240 |
void slotFileDeleted(const QString& folder, const QString& file, bool status); |
| 241 |
void slotFileUploaded(const ShowfotoItemInfo& info); |
| 242 |
|
| 243 |
protected: |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
void requestIncrementalRefresh(); |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
void startIncrementalRefresh(); |
| 258 |
void finishIncrementalRefresh(); |
| 259 |
|
| 260 |
void emitDataChangedForAll(); |
| 261 |
void emitDataChangedForSelections(const QItemSelection& selection); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
virtual void showfotoItemInfosCleared() {}; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
virtual void showfotoItemInfosAboutToBeRemoved(int , int ) {}; |
| 272 |
|
| 273 |
private: |
| 274 |
|
| 275 |
void appendInfos(const QList<ShowfotoItemInfo>& infos); |
| 276 |
void publiciseInfos(const QList<ShowfotoItemInfo>& infos); |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
void removeRowPairs(const QList<QPair<int, int> >& toRemove); |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
static QList<IntPair> toContiguousPairs(const QList<int>& unsorted); |
| 285 |
|
| 286 |
public: |
| 287 |
|
| 288 |
|
| 289 |
class Private; |
| 290 |
|
| 291 |
private: |
| 292 |
|
| 293 |
|
| 294 |
ShowfotoItemModel(const ShowfotoItemModel&) = delete; |
| 295 |
ShowfotoItemModel& operator=(const ShowfotoItemModel&) = delete; |
| 296 |
|
| 297 |
private: |
| 298 |
|
| 299 |
Private* const d = nullptr; |
| 300 |
}; |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
Q_DECLARE_METATYPE(ShowFoto::ShowfotoItemModel*) |