/*

Copyright (c) 2018, John Smith

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

*/


#ifndef FRAMERANGESMODEL_H
#define FRAMERANGESMODEL_H

#include <QAbstractTableModel>


struct FrameRange {
    int first;
    int last;
};


class FrameRangesModel : public QAbstractTableModel, public std::map<int, FrameRange> {
    Q_OBJECT

    enum Columns {
        FirstColumn = 0,
        LastColumn,
        ColumnCount
    };

public:
    FrameRangesModel(QObject *parent = Q_NULLPTR);

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

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

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;

    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

    using std::map<int, FrameRange>::cbegin;
    using std::map<int, FrameRange>::cend;
    using std::map<int, FrameRange>::upper_bound;
    using std::map<int, FrameRange>::count;
    using std::map<int, FrameRange>::size;

    void insert(const std::pair<int, FrameRange> &range);

    void erase(int frame);
};

#endif // FRAMERANGESMODEL_H
