summaryrefslogtreecommitdiff
path: root/src/main-view/DictTableModel.h
blob: 0293ace828867187bce47c1a81d876b6065e8953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef DICTTABLEMODEL_H
#define DICTTABLEMODEL_H

#include <QtCore>
#include <QtWidgets>

class Dictionary;
class DicRecord;

class DictTableModel: public QAbstractTableModel
{
    Q_OBJECT

public:
    enum
    {
        DicRecordRole = Qt::UserRole
    };
    
    DictTableModel( Dictionary* aDict, QObject *parent = 0 );
    
    // Getters

    const Dictionary* dictionary() const { return m_dictionary; }
    QUndoStack* undoStack() const { return m_undoStack; }
    
    Qt::ItemFlags flags( const QModelIndex& index ) const { return QAbstractItemModel::flags( index ) | Qt::ItemIsEditable; }
    int rowCount( const QModelIndex& parent = QModelIndex() ) const;
    int columnCount( const QModelIndex& parent = QModelIndex() ) const;
    QVariant data(const QModelIndex& index, int role) const;
    QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
    
    // Setters
    
    bool setData( const QModelIndex &index, const QVariant& value, int role = Qt::EditRole );
    bool insertRows( int position, int rows, const QModelIndex& index = QModelIndex() );
    bool addFields( QStringList aFields );
    bool removeRows( int position, int rows, const QModelIndex& index = QModelIndex() );

public slots:
    void resetData();

private slots:
    void discardCurDictionary();

private:
    static const int ThumbnailSize = 25;    ///< Size of image thumbnails

    Dictionary* m_dictionary;       // not own
    QUndoStack* m_undoStack;
};
#endif