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

0001 /****************************************************************************************
0002  * Copyright (c) 2008-2012 Soren Harward <stharward@gmail.com>                          *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef APG_CONSTRAINTGROUP
0018 #define APG_CONSTRAINTGROUP
0019 
0020 #include "ui_ConstraintGroupEditWidget.h"
0021 
0022 #include "ConstraintNode.h"
0023 
0024 #include "core/meta/forward_declarations.h"
0025 
0026 #include <QDomElement>
0027 #include <QHash>
0028 #include <QList>
0029 #include <QObject>
0030 #include <QString>
0031 #include <QtGlobal>
0032 #include <cmath>
0033 
0034 namespace Collections {
0035     class QueryMaker;
0036 }
0037 
0038 class ConstraintGroup : public ConstraintNode {
0039     Q_OBJECT
0040     public:
0041         enum MatchType { MatchAny, MatchAll };
0042 
0043         static ConstraintGroup* createFromXml( QDomElement&, ConstraintNode* );
0044         static ConstraintGroup* createNew( ConstraintNode* );
0045 
0046         QString getName() const override;
0047         int getNodeType() const override { return ConstraintNode::ConstraintGroupType; }
0048         QWidget* editWidget() const override;
0049         void toXml( QDomDocument&, QDomElement& ) const override;
0050 
0051         Collections::QueryMaker* initQueryMaker( Collections::QueryMaker* ) const override;
0052         double satisfaction( const Meta::TrackList& ) const override;
0053         quint32 suggestPlaylistSize() const override;
0054 
0055     private Q_SLOTS:
0056         void setMatchAny();
0057         void setMatchAll();
0058 
0059     private:
0060         ConstraintGroup(QDomElement&, ConstraintNode*);
0061         explicit ConstraintGroup(ConstraintNode*);
0062 
0063         // parameters
0064         MatchType m_matchtype;
0065 
0066         // internal mathematical functions
0067         double combineInterdependentConstraints( const Meta::TrackList&, const double, const QHash<int,int>& ) const;
0068 };
0069 
0070 class ConstraintGroupEditWidget : public QWidget {
0071     Q_OBJECT
0072 
0073     public:
0074         explicit ConstraintGroupEditWidget( const ConstraintGroup::MatchType );
0075 
0076     Q_SIGNALS:
0077         void updated();
0078         void clickedMatchAll();
0079         void clickedMatchAny();
0080 
0081     private Q_SLOTS:
0082         void on_radioButton_MatchAll_clicked( bool );
0083         void on_radioButton_MatchAny_clicked( bool );
0084 
0085     private:
0086         Ui::ConstraintGroupEditWidget ui;
0087 };
0088 
0089 #endif