File indexing completed on 2025-01-19 03:59:38

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-01-20
0007  * Description : User interface for searches
0008  *
0009  * SPDX-FileCopyrightText: 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "searchfields_p.h"
0017 
0018 namespace Digikam
0019 {
0020 
0021 SearchFieldText::SearchFieldText(QObject* const parent)
0022     : SearchField(parent),
0023       m_edit     (nullptr)
0024 {
0025 }
0026 
0027 void SearchFieldText::setupValueWidgets(QGridLayout* layout, int row, int column)
0028 {
0029     m_edit = new QLineEdit;
0030     layout->addWidget(m_edit, row, column, 1, 3);
0031 
0032     connect(m_edit, SIGNAL(textChanged(QString)),
0033             this, SLOT(valueChanged(QString)));
0034 }
0035 
0036 void SearchFieldText::read(SearchXmlCachingReader& reader)
0037 {
0038     QString value = reader.value();
0039     m_edit->setText(value);
0040 }
0041 
0042 void SearchFieldText::write(SearchXmlWriter& writer)
0043 {
0044     QString value = m_edit->text();
0045 
0046     if (!value.isEmpty())
0047     {
0048         writer.writeField(m_name, SearchXml::Like);
0049         writer.writeValue(value);
0050         writer.finishField();
0051     }
0052 }
0053 
0054 void SearchFieldText::reset()
0055 {
0056     m_edit->setText(QString());
0057 }
0058 
0059 void SearchFieldText::setValueWidgetsVisible(bool visible)
0060 {
0061     m_edit->setVisible(visible);
0062 }
0063 
0064 QList<QRect> SearchFieldText::valueWidgetRects() const
0065 {
0066     QList<QRect> rects;
0067     rects << m_edit->geometry();
0068 
0069     return rects;
0070 }
0071 
0072 void SearchFieldText::valueChanged(const QString& text)
0073 {
0074     setValidValueState(!text.isEmpty());
0075 }
0076 
0077 } // namespace Digikam