// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@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.



// Data object linking the vertical axis window with the core module performing the calculations
#include "yaxisdataobject.h"
#include <QMessageBox>
#include <QLocale>
#include <QString>
#include <QLocale>
#include "math.h"

YAxisDataObject::YAxisDataObject(QObject *parent, BytranCore *inCore) : QObject(parent)
{
    // Passing in the core object
    core = inCore;

    // So that commas are not inserted into numbers
    loc.setNumberOptions(QLocale::OmitGroupSeparator);

    // Saving units
    m_units = core->getYAxis()->getYPlotUnits();

    // Transfering the minimum to the QML interface component
    m_minimum = loc.toString(core->getYAxis()->getMinYPlot(), 'g', 6);

    // Transfering the maximum to the QML interface component
    m_maximum = loc.toString(core->getYAxis()->getMaxYPlot(), 'g', 6);

}

YAxisDataObject::YAxisDataObject(const QString &minimum, const QString &maximum, const int &units, QObject *parent)
    : QObject(parent), m_units(units), m_minimum(minimum), m_maximum(maximum)
{
    ;
}

QString YAxisDataObject::minimum() const
{
    return m_minimum;
}
void YAxisDataObject::setMinimum(const QString &minimum)
{
    if (minimum != m_minimum) {
        m_minimum = minimum;
        // Saving the wavelength into the internal dataset variable
        core->getYAxis()->setMinYPlot(loc.toDouble(m_minimum));
        emit minimumChanged();
    }
}

QString YAxisDataObject::maximum() const
{
    return m_maximum;
}
void YAxisDataObject::setMaximum(const QString &maximum)
{
    if (maximum != m_maximum) {
        m_maximum = maximum;
        // Saving the wavelength into the internal dataset variable
        core->getYAxis()->setMaxYPlot(loc.toDouble(m_maximum));
        emit maximumChanged();
    }
}

int YAxisDataObject::units() const
{
    return m_units;
}

void YAxisDataObject::setUnits(const int &units)
{
    if (units != m_units) {
        m_units = units;
        // Saving the units into the object used to convert to different pathlength measurement units
        core->getYAxis()->setYPlotUnits(m_units);
        emit minimumChanged();
        emit maximumChanged();
        emit unitsChanged();
    }
}
