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_CONSTRAINTNODE
0018 #define APG_CONSTRAINTNODE
0019 
0020 #include "core/meta/forward_declarations.h"
0021 
0022 #include <QDomElement>
0023 #include <QList>
0024 #include <QObject>
0025 #include <QString>
0026 
0027 namespace Collections {
0028     class QueryMaker;
0029 }
0030 
0031 class QWidget;
0032 
0033 /* Abstract base class for all constraints, including ConstraintGroup
0034  *
0035  * Inheritance Tree:
0036  *
0037  *                       ConstraintNode
0038  *                              |
0039  *             +----------------+-----------+
0040  *             |                            |
0041  *      ConstraintGroup                 Constraint
0042  *                                          |
0043  *          +-----------------+-------------+-----+--------  ... etc
0044  *          |                 |                   |
0045  *      Matching     PreventDuplicates     PlaylistDuration
0046  *          |
0047  *      TagMatch
0048  *
0049  *
0050  * If you want to write a new Constraint, don't subclass this directly.
0051  * Subclass Constraint or one of its children instead. -- sth
0052  */
0053 
0054 class ConstraintNode : public QObject {
0055     Q_OBJECT
0056     public:
0057         enum NodeType { ConstraintGroupType, ConstraintType };
0058 
0059         ~ConstraintNode() override;
0060 
0061         // Functions used in ConstraintModel
0062         int row() const;
0063         int getRowCount() const;
0064 
0065         ConstraintNode* parent() const;
0066         bool addChild( ConstraintNode*, int );
0067         ConstraintNode* getChild( int );
0068         ConstraintNode* pruneChild( int );
0069         bool removeChild( int );
0070 
0071         virtual QString getName() const = 0;
0072         virtual int getNodeType() const = 0;
0073         virtual QWidget* editWidget() const = 0;
0074         virtual void toXml( QDomDocument&, QDomElement& ) const = 0;
0075 
0076         // Set up the initial query for the ConstraintSolver
0077         virtual Collections::QueryMaker* initQueryMaker( Collections::QueryMaker* qm ) const { return qm; }
0078 
0079         // Mathematical function called by the ConstraintSolver
0080         virtual double satisfaction( const Meta::TrackList& ) const = 0;
0081 
0082         // heuristic functions for the ConstraintSolver
0083         virtual quint32 suggestPlaylistSize() const;
0084 
0085     Q_SIGNALS:
0086         void dataChanged();
0087 
0088     protected:
0089         ConstraintNode(ConstraintNode* parent);
0090         int where_is(const ConstraintNode*) const;
0091 
0092         QList<ConstraintNode*> m_children;
0093 };
0094 
0095 #endif