// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | bytran@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// This is a "QAbstractItemModel" class used to display and change data in the QML molecules list view
#ifndef MOLLISTVIEWREDUCEDMODEL_H
#define MOLLISTVIEWREDUCEDMODEL_H

#include <QObject>
#include <QAbstractListModel>
#include "bytrancore.h"

class MolListViewReduced
{
public:

    MolListViewReduced(const QString &molName, const QString &color);

    QString molName() const;
    QString color() const;

    void setPressValue(const QString &pressValue);
    void setColor(const QString &color);

private:

    QString m_molName;
    QString m_color;

};

class MolListViewReducedModel : public QAbstractListModel
{
    Q_OBJECT

public:

    // Method to update the partial pressures displayed in the molecules window
    Q_INVOKABLE void updateDisplayed();

    enum MolListViewReducedRoles {
        molNameRole = Qt::UserRole + 1,
        colorRole
    };

    MolListViewReducedModel(QObject *parent = 0, BytranCore *inCore = 0);

    void addElement(const MolListViewReduced &molListView);
    void removeAllElements();
    // void clear();
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

    // Method to set the data when the values in the model are modified
    bool setData(const QModelIndex & index, const QVariant & value, int role);

signals:

    // Signals to notify of select all changed and units changed states

protected:

    QHash<int, QByteArray> roleNames() const;

private:

    BytranCore *core;
    QList<MolListViewReduced> m_molListView;
    int m_units;   // Units of concentration to be used to specify the partial pressures
    QString m_selectedColor;  // String with the HEX representation of the selected color
    int m_activeIndex;  // Index of the currently active molecule in the list
    bool m_allSelected;   // Variable holds the state of if all molecules are selected or not

};

#endif // MOLLISTVIEWREDUCEDMODEL_H
