File indexing completed on 2024-05-12 16:40:01

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KEXIFINDDIALOG_H
0021 #define KEXIFINDDIALOG_H
0022 
0023 #include "ui_kexifinddialog.h"
0024 #include <core/kexisearchandreplaceiface.h>
0025 
0026 #include <QDialog>
0027 
0028 class QAction;
0029 
0030 //! @short A Kexi-specific "Find" dialog.
0031 /*! Also used for as replace dialog.
0032 
0033  @todo replace m_textToFind and m_textToReplace KComboBoxes with Kexi's db-aware comboboxes,
0034        so we ca adapt to datatype being searched, e.g. date, time and numbers
0035 */
0036 class KexiFindDialog : public QDialog, private Ui::KexiFindDialog
0037 {
0038     Q_OBJECT
0039 public:
0040     //! Creates a new find dialog. Replace mode is off by default.
0041     explicit KexiFindDialog(QWidget* parent);
0042     virtual ~KexiFindDialog();
0043 
0044     //! Sets actions that receive button clicks and shortcuts within the dialog. Should be called once.
0045     void setActions(QAction *findnext, QAction *findprev,
0046                     QAction *replace, QAction *replaceall);
0047 
0048     //! Shows the dialog as a modal dialog.
0049     virtual void show();
0050 
0051     //! \return current find and replace options set within the dialog
0052 //! @todo should we have setOptions() too?
0053     KexiSearchAndReplaceViewInterface::Options options() const;
0054 
0055     /*! \return a list of column names for 'look in column' combo box.
0056      Neither "(All fields)" nor "(Current field)" items are prepended. */
0057     QStringList lookInColumnNames() const;
0058 
0059     /*! \return a list of column captions (i.e. visible values) for 'look in column' combo box.
0060      Neither "(All fields)" nor "(Current field)" items are prepended. */
0061     QStringList lookInColumnCaptions() const;
0062 
0063     /*! \return column name selected in "look in column" combo box.
0064      If "(All fields)" item is selected, empty string is returned.
0065      If "(Current field)" item is selected, "(field)" string is returned. */
0066     QString currentLookInColumnName() const;
0067 
0068     //! \return value that to be used for searching
0069     QVariant valueToFind() const;
0070 
0071     //! \return value that to be used as a replacement
0072     QVariant valueToReplaceWith() const;
0073 
0074 public Q_SLOTS:
0075     /*! Sets \a columnNames list and \a columnCaptions for 'look in column' combo box.
0076      \a columnCaptions are visible values, while \a columnNames are used for returning
0077      in currentLookInColumn().
0078      "(All fields)" and "(Current field)" items are also prepended. */
0079     void setLookInColumnList(const QStringList& columnNames,
0080                              const QStringList& columnCaptions);
0081 
0082     /*! Selects \a columnName to be selected 'look in column'.
0083      By default "(All fields)" item is selected. To select this item,
0084      pass empty string as \a columnName.
0085      To select "(Current field)" item, "(field)" string should be passed
0086      as \a columnName. */
0087     void setCurrentLookInColumnName(const QString& columnName);
0088 
0089     /*! Sets or clears replace mode.
0090      For replace mode 'prompt or replace' option is visible. */
0091     void setReplaceMode(bool set);
0092 
0093     /*! Sets object name for caption, so for example it will be set
0094      to xi18n("Find \"Persons\"")). */
0095     void setObjectNameForCaption(const QString& name);
0096 
0097     /*! Enables of disables the find/replace/replace all buttons.
0098      This is used if for the current context the dialog could not be used.
0099      If \a enable is false, object name for caption is cleared
0100      using setObjectNameForCaption() too. */
0101     void setButtonsEnabled(bool enable);
0102 
0103     /*! Sets message at the bottom to \a message. */
0104     void setMessage(const QString& message);
0105 
0106     /*! Updates message at the bottom; "The search item was not found" is set if \a found is true,
0107      else the message is cleared. */
0108 //! @todo add "Search again" hyperlink
0109     void updateMessage(bool found = true);
0110 
0111     void addToFindHistory();
0112     void addToReplaceHistory();
0113 
0114 Q_SIGNALS:
0115     //! Emitted after clicking "Find next" button or pressing appropriate shortcut set by setActions()
0116     void findNext();
0117 
0118     //! Emitted after pressing appropriate shortcut set by setActions()
0119     void findPrevious();
0120 
0121     //! Emitted after clicking "Replace" button or pressing appropriate shortcut set by setActions()
0122     void replaceNext();
0123 
0124     //! Emitted after clicking "Replace All" button or pressing appropriate shortcut set by setActions()
0125     void replaceAll();
0126 
0127 protected Q_SLOTS:
0128     void updateMessage(const QString&) {
0129         updateMessage();
0130     }
0131 
0132 protected:
0133     bool event(QEvent *e) override;
0134 
0135     class Private;
0136     Private * const d;
0137 };
0138 
0139 #endif