/****************************************************************************
*
*  Copyright (C) 2002-2015 Helta Kft. - NociSoft Software Solutions
*  All rights reserved.
*  Author: Norbert Szabo
*  E-mail: norbert@nocisoft.com, office@nocisoft.com
*  Web: www.nocisoft.com
*
*  Created: 2015. 01. 07. (nszabo)
*  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
*  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
****************************************************************************/

#ifndef NCREPORTDATAFORMAT_H
#define NCREPORTDATAFORMAT_H

#include "ncreportdata.h"

#include <QChar>
#include <QVariant>

class NCReportFieldItem;
class NCReportEvaluator;

class NCReportDataFormat
{
public:
    NCReportDataFormat( NCReportEvaluator* ev );
    ~NCReportDataFormat();

    void setDataType( NCReportData::DataType dt ) {m_type = dt;}
    void setValue( const QVariant& value ) {m_value = value;}
    void setNumberIsFormatted(bool set) { m_formatNum = set; }
    void setLocalized(bool set) { m_localized = set; }
    void setFieldWidth(int width) { m_fieldwidth = width; }
    void setNumericFormat(const char format) { m_format = format; }
    void setPrecision(int precision) { m_precision = precision; }
    void setFillChar( const QChar& fillChar) { m_fillchar = fillChar; }
    void setBlankIfZero(bool set) { m_blankIfZero = set; }
    void setDateFormat( const QString& format ) { m_dateFormat = format; }
    void setArg(const QString& arg) { m_arg = arg; }
    void setNumChars(int width) { m_numChars = width; }
    void setAlignment( Qt::Alignment alignment ) { m_alignment = alignment; }
    void setNumSubstitutionStringIfZero( bool set ) { m_isZeroSubstitution = set; }
    void setNumSubstitutionString( const QString & string ) { m_zeroSubstitutionString = string; }

    QString formattedData();

    void formatData(QString &result);
    void formatField( NCReportFieldItem *field );

private:
    NCReportData::DataType m_type;
    QVariant m_value;
    NCReportEvaluator* m_evaluator;

    bool m_formatNum;
    bool m_localized;
    int m_fieldwidth;
    char m_format;
    int m_precision;
    QChar m_fillchar;
    bool m_blankIfZero;
    int m_numChars;
    bool m_isZeroSubstitution;

    QString m_dateFormat;
    QString m_arg;
    QString m_zeroSubstitutionString;
    Qt::Alignment m_alignment;

private:
    void formatString(QString& result);
    void formatNumber(QString& result);
    void formatDate(QString& result);
    void formatDateTime(QString& result);
    void formatTime(QString& result);
    void formatBool(QString& result);


};

#endif // NCREPORTDATAFORMAT_H
