File indexing completed on 2024-04-14 04:36:55

0001 /***************************************************************************
0002  *   Copyright (C) 2018 by Emmanuel Lepage Vallee                          *
0003  *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org>             *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 3 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0017  **************************************************************************/
0018 #ifndef KQUICKITEMVIEWS_DELEGATECHOICE_H
0019 #define KQUICKITEMVIEWS_DELEGATECHOICE_H
0020 
0021 // Qt
0022 #include <QQmlComponent>
0023 #include <QQmlScriptString>
0024 #include <QtCore/QVariant>
0025 
0026 class DelegateChoicePrivate;
0027 
0028 class Q_DECL_EXPORT DelegateChoice : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032 
0033     Q_PROPERTY(int column READ column WRITE setColumn NOTIFY changed)
0034     Q_PROPERTY(int row READ row WRITE setRow NOTIFY changed)
0035     Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY changed)
0036 
0037     /// Either an `int` or a `QModelIndex`
0038     Q_PROPERTY(QVariant index READ index WRITE setIndex NOTIFY changed)
0039     Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY changed)
0040 
0041     Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY changed)
0042 
0043     /**
0044      * A JavaScript expression with access to all role values.
0045      */
0046     Q_PROPERTY(QQmlScriptString when READ when WRITE setWhen NOTIFY changed)
0047 
0048     explicit DelegateChoice(QObject *parent = nullptr);
0049     virtual ~DelegateChoice();
0050 
0051     int column() const;
0052     void setColumn(int c);
0053 
0054     int row() const;
0055     void setRow(int r);
0056 
0057     int depth() const;
0058     void setDepth(int d);
0059 
0060     QVariant index() const;
0061     void setIndex(const QVariant& i);
0062 
0063     QQmlComponent *delegate() const;
0064     void setDelegate(QQmlComponent *d);
0065 
0066     QQmlScriptString when() const;
0067     void setWhen(const QQmlScriptString &w);
0068 
0069     QVariant roleValue() const;
0070     void setRoleValue(const QVariant &v);
0071 
0072 protected:
0073     virtual bool evaluateIndex(const QModelIndex& idx);
0074     virtual bool evaluateRow(int row, const QModelIndex& parent);
0075     virtual bool evaluateColumn(int row, const QModelIndex& parent);
0076 
0077 Q_SIGNALS:
0078     void changed();
0079 
0080 private:
0081     DelegateChoicePrivate *d_ptr;
0082     Q_DECLARE_PRIVATE(DelegateChoice)
0083 };
0084 
0085 #endif