File indexing completed on 2025-04-27 03:58:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-06-13 0007 * Description : A QCompleter for AbstractAlbumModels 0008 * 0009 * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009-2010 by Johannes Wienke <languitar at semipol dot de> 0011 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #ifndef DIGIKAM_MODEL_COMPLETER_H 0018 #define DIGIKAM_MODEL_COMPLETER_H 0019 0020 // QT includes 0021 0022 #include <QAbstractItemModel> 0023 #include <QStringList> 0024 #include <QCompleter> 0025 0026 // Local includes 0027 0028 #include "digikam_export.h" 0029 0030 namespace Digikam 0031 { 0032 0033 class DIGIKAM_EXPORT ModelCompleter : public QCompleter 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 0039 explicit ModelCompleter(QObject* const parent = nullptr); 0040 ~ModelCompleter() override; 0041 0042 /** 0043 * If the given model is != null, the model is used to populate the 0044 * completion for this text field. 0045 * 0046 * @param model to fill from or null for manual mode 0047 * @param uniqueIdRole a role for which the model will return a unique integer for each entry 0048 * @param displayRole the role to retrieve the text for completion, default is Qt::DisplayRole. 0049 */ 0050 void setItemModel(QAbstractItemModel* const model, int uniqueIdRole, int displayRole = Qt::DisplayRole); 0051 QAbstractItemModel* itemModel() const; 0052 0053 void addItem(const QString& item); 0054 void setList(const QStringList& list); 0055 QStringList items() const; 0056 0057 Q_SIGNALS: 0058 0059 void signalHighlighted(int albumId); 0060 void signalActivated(); 0061 0062 private Q_SLOTS: 0063 0064 void slotDelayedModelTimer(); 0065 void slotHighlighted(const QModelIndex& index); 0066 void slotRowsInserted(const QModelIndex& parent, int start, int end); 0067 void slotRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end); 0068 void slotDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); 0069 void slotModelReset(); 0070 0071 private: 0072 0073 void sync(QAbstractItemModel* const model); 0074 void sync(QAbstractItemModel* const model, const QModelIndex& index); 0075 0076 private: 0077 0078 class Private; 0079 Private* const d; 0080 }; 0081 0082 } // namespace Digikam 0083 0084 #endif // DIGIKAM_MODEL_COMPLETER_H