2017-11-06 11:42:13 +01:00
|
|
|
|
2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2017-01-23 13:42:40 +01:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017 Kyle Robbertze <kyle@aims.ac.za>
|
|
|
|
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2017-01-23 13:42:40 +01:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2017-01-23 13:42:40 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PACKAGEMODEL_H
|
|
|
|
#define PACKAGEMODEL_H
|
|
|
|
|
|
|
|
#include "PackageTreeItem.h"
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2019-04-17 11:43:21 +02:00
|
|
|
namespace YAML
|
|
|
|
{
|
2020-02-18 11:02:53 +01:00
|
|
|
class Node;
|
2019-04-17 11:43:21 +02:00
|
|
|
}
|
2017-01-23 13:42:40 +01:00
|
|
|
|
|
|
|
class PackageModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2017-01-23 14:04:07 +01:00
|
|
|
public:
|
2020-03-10 18:22:56 +01:00
|
|
|
// Names for columns (unused in the code)
|
|
|
|
static constexpr const int NameColumn = 0;
|
|
|
|
static constexpr const int DescriptionColumn = 1;
|
|
|
|
|
|
|
|
/* The only interesting roles are DisplayRole (with text depending
|
|
|
|
* on the column, and MetaExpandRole which tells if an index
|
|
|
|
* should be initially expanded.
|
|
|
|
*/
|
|
|
|
static constexpr const int MetaExpandRole = Qt::UserRole + 1;
|
|
|
|
|
2020-03-24 12:36:31 +01:00
|
|
|
explicit PackageModel( QObject* parent = nullptr );
|
2017-09-13 20:07:09 +02:00
|
|
|
~PackageModel() override;
|
2017-01-23 13:42:40 +01:00
|
|
|
|
2020-03-24 12:36:31 +01:00
|
|
|
void setupModelData( const QVariantList& l );
|
|
|
|
|
2017-01-25 09:34:18 +01:00
|
|
|
QVariant data( const QModelIndex& index, int role ) const override;
|
2020-02-18 11:02:53 +01:00
|
|
|
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override;
|
2017-01-25 09:34:18 +01:00
|
|
|
Qt::ItemFlags flags( const QModelIndex& index ) const override;
|
2020-02-19 12:51:01 +01:00
|
|
|
|
2020-02-18 11:02:53 +01:00
|
|
|
QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
|
2017-01-25 09:34:18 +01:00
|
|
|
QModelIndex parent( const QModelIndex& index ) const override;
|
2020-02-19 12:51:01 +01:00
|
|
|
|
|
|
|
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
|
2017-01-25 09:34:18 +01:00
|
|
|
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
|
|
|
|
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
|
2020-02-19 12:51:01 +01:00
|
|
|
|
2022-01-24 22:39:14 +01:00
|
|
|
/** @brief Sets the checked flag on matching groups in the tree
|
|
|
|
*
|
|
|
|
* Recursively traverses the tree pointed to by m_rootItem and
|
|
|
|
* checks if a group name matches any of the items in @p selectNames.
|
|
|
|
* If a match is found, set check the box for that group and it's children.
|
|
|
|
*
|
|
|
|
* Individual packages will not be matched.
|
|
|
|
*
|
|
|
|
*/
|
2022-01-31 23:41:48 +01:00
|
|
|
void setSelections( const QStringList& selectNames );
|
2022-01-15 16:41:23 +01:00
|
|
|
|
2020-03-20 23:03:47 +01:00
|
|
|
PackageTreeItem::List getPackages() const;
|
|
|
|
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
|
2017-01-23 13:42:40 +01:00
|
|
|
|
2022-01-31 12:55:54 +01:00
|
|
|
/** @brief Appends groups to the tree
|
|
|
|
*
|
|
|
|
* Uses the data from @p groupList to add elements to the
|
|
|
|
* existing tree that m_rootItem points to. If m_rootItem
|
|
|
|
* is not valid, it does nothing
|
|
|
|
*
|
|
|
|
* Before adding anything to the model, it ensures that there
|
|
|
|
* is no existing data from the same source. If there is, that
|
|
|
|
* data is pruned first
|
|
|
|
*
|
|
|
|
*/
|
2022-01-31 23:41:48 +01:00
|
|
|
void appendModelData( const QVariantList& groupList );
|
2022-01-15 16:41:23 +01:00
|
|
|
|
2017-01-23 14:04:07 +01:00
|
|
|
private:
|
2020-03-23 12:53:35 +01:00
|
|
|
friend class ItemTests;
|
|
|
|
|
2020-03-22 15:09:43 +01:00
|
|
|
void setupModelData( const QVariantList& l, PackageTreeItem* parent );
|
2017-01-23 13:42:40 +01:00
|
|
|
|
2020-03-24 12:36:31 +01:00
|
|
|
PackageTreeItem* m_rootItem = nullptr;
|
2020-03-20 23:03:47 +01:00
|
|
|
PackageTreeItem::List m_hiddenItems;
|
2017-01-23 13:42:40 +01:00
|
|
|
};
|
|
|
|
|
2020-02-18 11:02:53 +01:00
|
|
|
#endif // PACKAGEMODEL_H
|