File indexing completed on 2025-01-19 03:53:49

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-11-25
0007  * Description : a bar used to search a string - version based on database models
0008  *
0009  * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "searchtextbardb.h"
0016 
0017 // Qt includes
0018 
0019 #include <QContextMenuEvent>
0020 #include <QMenu>
0021 #include <QColor>
0022 #include <QPalette>
0023 #include <QString>
0024 #include <QMap>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 #include <kconfiggroup.h>
0030 
0031 // Local includes
0032 
0033 #include "digikam_debug.h"
0034 #include "albumfiltermodel.h"
0035 
0036 namespace Digikam
0037 {
0038 
0039 class Q_DECL_HIDDEN SearchTextBarDb::Private
0040 {
0041 public:
0042 
0043     explicit Private()
0044       : filterModel(nullptr)
0045     {
0046     }
0047 
0048     QPointer<AlbumFilterModel> filterModel;
0049 };
0050 
0051 SearchTextBarDb::SearchTextBarDb(QWidget* const parent, const QString& name, const QString& msg)
0052     : SearchTextBar(parent, name, msg),
0053       d            (new Private)
0054 {
0055 }
0056 
0057 SearchTextBarDb::~SearchTextBarDb()
0058 {
0059     delete d;
0060 }
0061 
0062 void SearchTextBarDb::setModel(QAbstractItemModel* model, int uniqueIdRole, int displayRole)
0063 {
0064     completerModel()->setItemModel(model, uniqueIdRole, displayRole);
0065 }
0066 
0067 void SearchTextBarDb::setModel(AbstractAlbumModel* const model)
0068 {
0069     completerModel()->setItemModel(model, AbstractAlbumModel::AlbumIdRole, AbstractAlbumModel::AlbumTitleRole);
0070 }
0071 
0072 void SearchTextBarDb::setFilterModel(AlbumFilterModel* const filterModel)
0073 {
0074     // if there already was a model, disconnect from this model
0075 
0076     if (d->filterModel)
0077     {
0078         disconnect(d->filterModel);
0079     }
0080 
0081     d->filterModel = filterModel;
0082 
0083     // connect to new model if desired
0084 
0085     if (d->filterModel)
0086     {
0087         connect(this, SIGNAL(signalSearchTextSettings(SearchTextSettings)),
0088                 d->filterModel, SLOT(setSearchTextSettings(SearchTextSettings)));
0089 
0090         connect(d->filterModel, SIGNAL(hasSearchResult(bool)),
0091                 this, SLOT(slotSearchResult(bool)));
0092     }
0093 }
0094 
0095 } // namespace Digikam
0096 
0097 #include "moc_searchtextbardb.cpp"