1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef PHRASEMODEL_H
5#define PHRASEMODEL_H
6
7#include "phrase.h"
8
9#include <QList>
10#include <QAbstractItemModel>
11
12QT_BEGIN_NAMESPACE
13
14class PhraseModel : public QAbstractTableModel
15{
16 Q_OBJECT
17
18public:
19 PhraseModel(QObject *parent = 0)
20 : QAbstractTableModel(parent)
21 {}
22
23 void removePhrases();
24 QList<Phrase *> phraseList() const {return plist;}
25
26 QModelIndex addPhrase(Phrase *p);
27 void removePhrase(const QModelIndex &index);
28
29 Phrase *phrase(const QModelIndex &index) const;
30 void setPhrase(const QModelIndex &indx, Phrase *ph);
31 QModelIndex index(Phrase * const phr) const;
32 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
33 { return QAbstractTableModel::index(row, column, parent); }
34
35 // from qabstracttablemodel
36 int rowCount(const QModelIndex &) const override;
37 int columnCount(const QModelIndex &) const override;
38 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
39 QVariant headerData(int section, Qt::Orientation orientation,
40 int role = Qt::DisplayRole) const override;
41 Qt::ItemFlags flags(const QModelIndex &index) const override;
42 bool setData(const QModelIndex &index, const QVariant &value,
43 int role = Qt::EditRole) override;
44
45 // HACK: This model will be displayed in a _TreeView_
46 // which has a tendency to expand 'children' on double click
47 bool hasChildren(const QModelIndex &parent) const override
48 { return !parent.isValid(); }
49
50private:
51 QList<Phrase *> plist;
52};
53
54QT_END_NAMESPACE
55
56#endif // PHRASEMODEL_H
57

source code of qttools/src/linguist/linguist/phrasemodel.h