source: calamares/trunk/fuentes/src/modules/partition/core/PartitionModel.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 18 months ago

sync with github

File size: 3.8 KB
RevLine 
[7538]1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef PARTITIONMODEL_H
20#define PARTITIONMODEL_H
21
22#include "OsproberEntry.h"
23
24// Qt
25#include <QAbstractItemModel>
26
27class Device;
28class Partition;
29class PartitionNode;
30
31/**
32 * A Qt tree model which exposes the partitions of a device.
33 *
34 * Its depth is only more than 1 if the device has extended partitions.
35 *
36 * Note on updating:
37 *
38 * The Device class does not notify the outside world of changes on the
39 * Partition objects it owns. Since a Qt model must notify its views *before*
40 * and *after* making changes, it is important to make use of
41 * the PartitionModel::ResetHelper class to wrap changes.
42 *
43 * This is what PartitionCoreModule does when it create jobs.
44 */
45class PartitionModel : public QAbstractItemModel
46{
47    Q_OBJECT
48public:
49    /**
50     * This helper class must be instantiated on the stack *before* making
51     * changes to the device represented by this model. It will cause the model
52     * to emit modelAboutToBeReset() when instantiated and modelReset() when
53     * destructed.
54     */
55    class ResetHelper
56    {
57    public:
58        ResetHelper( PartitionModel* model );
59        ~ResetHelper();
60
61        ResetHelper( const ResetHelper& ) = delete;
62        ResetHelper& operator=( const ResetHelper& ) = delete;
63    private:
64        PartitionModel* m_model;
65    };
66
67    enum
68    {
69        // The raw size, as a qlonglong. This is different from the DisplayRole of
70        // SizeColumn, which is a human-readable string.
71        SizeRole = Qt::UserRole + 1,
72        IsFreeSpaceRole,
73        IsPartitionNewRole,
74        FileSystemLabelRole,
75        FileSystemTypeRole,
76        PartitionPathRole,
77        PartitionPtrRole,   // passed as void*, use sparingly
78        OsproberNameRole,
79        OsproberPathRole,
80        OsproberCanBeResizedRole,
81        OsproberRawLineRole,
82        OsproberHomePartitionPathRole
83    };
84
85    enum Column
86    {
87        NameColumn,
88        FileSystemColumn,
89        MountPointColumn,
90        SizeColumn,
91        ColumnCount // Must remain last
92    };
93
94    PartitionModel( QObject* parent = nullptr );
95    /**
96     * device must remain alive for the life of PartitionModel
97     */
98    void init( Device* device, const OsproberEntryList& osproberEntries );
99
100    // QAbstractItemModel API
101    QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
102    QModelIndex parent( const QModelIndex& child ) const override;
103    int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
104    int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
105    QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
106    QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
107
108    Partition* partitionForIndex( const QModelIndex& index ) const;
109
110    Device* device() const
111    {
112        return m_device;
113    }
114
115    void update();
116
117private:
118    Device* m_device;
119    OsproberEntryList m_osproberEntries;
120};
121
122#endif /* PARTITIONMODEL_H */
Note: See TracBrowser for help on using the repository browser.