File indexing completed on 2024-05-05 04:48:25

0001 /****************************************************************************************
0002  * Copyright (c) 2006 Giovanni Venturi <giovanni@kde-it.org>                            *
0003  * Copyright (c) 2010 Ralf Engels <ralf-engels@gmx.de>                                  *
0004  * Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com>                                 *
0005  *                                                                                      *
0006  * This program is free software; you can redistribute it and/or modify it under        *
0007  * the terms of the GNU General Public License as published by the Free Software        *
0008  * Foundation; either version 2 of the License, or (at your option) any later           *
0009  * version.                                                                             *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018  
0019 #ifndef AMAROK_EDITFILTERDIALOG_H
0020 #define AMAROK_EDITFILTERDIALOG_H
0021 
0022 #include "core/meta/forward_declarations.h"
0023 #include "widgets/MetaQueryWidget.h"
0024 #include "widgets/TokenPool.h"
0025 
0026 #include <QDialog>
0027 #include <QList>
0028 
0029 namespace Ui
0030 {
0031     class EditFilterDialog;
0032 }
0033 
0034 class EditFilterDialog : public QDialog
0035 {
0036     Q_OBJECT
0037 
0038     public:
0039         explicit EditFilterDialog( QWidget* parent, const QString &text = QString() );
0040         ~EditFilterDialog() override;
0041 
0042         QString filter();
0043 
0044     Q_SIGNALS:
0045         void filterChanged( const QString &filter );
0046 
0047     private Q_SLOTS:
0048         void slotTokenSelected( Token *token );
0049         void slotTokenRemoved( Token *token );
0050         void slotAttributeChanged( const MetaQueryWidget::Filter &filter );
0051         void slotInvert( bool checked );
0052         void slotSeparatorChange();
0053         void slotSearchEditChanged( const QString &filterText );
0054         void slotReset();
0055         void accept() override;
0056 
0057         void updateAttributeEditor();
0058         void updateSearchEdit();
0059 
0060         /** Parses the given text and set's the dropTarget accordingly. */
0061         void updateDropTarget( const QString &filterText );
0062 
0063     private:
0064         void initTokenPool();
0065         Token *tokenForField( const qint64 field );
0066 
0067         struct Filter
0068         {
0069             MetaQueryWidget::Filter filter;
0070             bool inverted;
0071         };
0072 
0073         Filter &filterForToken( Token *token );
0074 
0075         Ui::EditFilterDialog *m_ui;
0076         Token *m_curToken;
0077         QMap< Token *, Filter > m_filters;
0078 
0079         QString m_separator;
0080 
0081         /** True if we are already updating the status.
0082             This blocks recursive calls to updateWidgets or parsteTextFilters. */
0083         bool m_isUpdating;
0084 };
0085 
0086 #endif /* AMAROK_EDITFILTERDIALOG_H */