aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/coloring_rules_model.h
blob: f9cb6583ecefe55cdfd7a2069a7c433e94310e1f (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* coloring_rules_model.h
 * Data model for coloring rules.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef COLORING_RULES_MODEL_H
#define COLORING_RULES_MODEL_H

#include <config.h>

#include <glib.h>
#include <epan/color_filters.h>

#include <ui/qt/models/tree_model_helpers.h>

#include <QList>
#include <QColor>
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>

class ColoringRuleItem : public ModelHelperTreeItem<ColoringRuleItem>
{
public:
    ColoringRuleItem(bool disabled, QString name, QString filter, QColor foreground, QColor background, ColoringRuleItem* parent);
    virtual ~ColoringRuleItem();

    ColoringRuleItem(color_filter_t *colorf, ColoringRuleItem* parent);
    ColoringRuleItem(const ColoringRuleItem& item);

    bool disabled_;
    QString name_;
    QString filter_;
    QColor foreground_;
    QColor background_;

    ColoringRuleItem& operator=(ColoringRuleItem& rhs);

};

class ColoringRulesModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    ColoringRulesModel(QColor defaultForeground, QColor defaultBackground, QObject *parent);
    virtual ~ColoringRulesModel();

    enum ColoringRulesColumn {
        colName = 0,
        colFilter,
        colColoringRulesMax
    };

    void addColor(color_filter_t* colorf);
    void addColor(bool disabled, QString filter, QColor foreground, QColor background);
    bool importColors(QString filename, QString& err);
    bool exportColors(QString filename, QString& err);
    bool writeColors(QString& err);

    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant data(const QModelIndex &index, int role) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    QModelIndex index(int row, int column,
                      const QModelIndex & = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &) const;

    //Drag & drop functionality
    Qt::DropActions supportedDropActions() const;
    QStringList mimeTypes() const;
    QMimeData* mimeData(const QModelIndexList &indexes) const;
    bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
    bool copyRow(int dst_row, int src_row);

private:
    void populate();
    struct _GSList *createColorFilterList();

    ColoringRuleItem* root_;
    //Save off the conversation colors, do not include in dialog
    struct _GSList *conversation_colors_;

    QColor defaultForeground_;
    QColor defaultBackground_;

    QList<int> dragDropRows_;
};

#endif // COLORING_RULES_MODEL_H