Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: Format number 99.999.999  (Read 6410 times)

kkborrame@gmail.com

  • Newbie
  • *
  • Posts: 3
    • View Profile
Format number 99.999.999
« on: March 01, 2016, 09:24:02 pm »
Hi. It's posible format a number like 12.345.678?
I need show it with thousand separator.
Thanks.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Format number 99.999.999
« Reply #1 on: March 02, 2016, 01:05:05 am »
Unfortunately, in the current version(1.3.10) there is no easy way to do it.
But we have added an "Locale" argument to the "numberFormat" script function and pushed changes to GitHub (https://github.com/fralx/LimeReport).
You can get the source code from there or wait for the next release at sourceforge.net. After that, you will be able to use the function like this :
Code: [Select]
$S{numberFormat($D{table.value},"f",2,"gb")}The function result will be number with separators.

kkborrame@gmail.com

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Format number 99.999.999
« Reply #2 on: March 02, 2016, 12:21:09 pm »
Thanks.
It worked perfectly.

I changed the library that perhaps might interest you . I have a PreviewReportWidget class. If you want to send you some code let me know.
A greeting.
Thank you.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Format number 99.999.999
« Reply #3 on: March 02, 2016, 11:13:35 pm »
kkborrame@gmail.com, It will be interesting.

kkborrame@gmail.com

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Format number 99.999.999
« Reply #4 on: March 03, 2016, 01:31:44 pm »
#include "lrpreviewreportwidget.h"
#include "ui_lrpreviewreportwidget.h"


#include "lrpagedesignintf.h"
#include "serializators/lrstorageintf.h"
#include "serializators/lrxmlreader.h"

#include "serializators/lrxmlreader.h"
#include "serializators/lrxmlwriter.h"
#include "lrreportengine_p.h"

#include <QPrinter>
#include <QPrintDialog>
#include <QFileDialog>
#include <QScrollBar>
#include <QDesktopWidget>

PreviewReportWidget::PreviewReportWidget(ReportEnginePrivate *report, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PreviewReportWidget)
{
    ui->setupUi(this);

    m_currentPage  = 1;
    m_changingPage = false;
    m_priorScrolValue = 0;

    m_report = report;
    m_previewPage = m_report->createPreviewPage();
    m_previewPage->setItemMode( LimeReport::PreviewMode );
    connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int)));
}

PreviewReportWidget::~PreviewReportWidget()
{
    delete ui;
}

void PreviewReportWidget::actualiza()
{
    //QTime start = QTime::currentTime();
    m_report->dataManager()->setDesignTime(false);
    m_reportPages = m_report->renderToPages();
    m_report->dataManager()->setDesignTime(true);

    if (!m_reportPages.isEmpty()){
        //m_previewPage->setPageItem(m_reportPages.at(0));
        m_previewPage->setPageItems(m_reportPages);
        m_changingPage = true;

        ui->graphicsView->setScene(m_previewPage);
        ui->graphicsView->centerOn(0, 0);
        ui->graphicsView->scale(0.5,0.5);

        m_currentPage = 1;
        emit pageChanged(m_currentPage);
        if (m_reportPages.at(0)) m_reportPages.at(0)->setSelected(true);
        m_changingPage = false;

        //qDebug()<<"render time ="<<start.msecsTo(QTime::currentTime());
    }
}

void PreviewReportWidget::slotZoomIn()
{
    ui->graphicsView->scale(1.2,1.2);
}

void PreviewReportWidget::slotZoomOut()
{
    ui->graphicsView->scale(1/1.2,1/1.2);
}

void PreviewReportWidget::slotFirstPage()
{
    m_changingPage=true;
    if ((!m_reportPages.isEmpty())&&(m_currentPage>1)){
        m_currentPage=1;
        ui->graphicsView->ensureVisible(
                    calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
        );
        emit pageChanged(m_currentPage);
    }
    m_changingPage=false;
}

void PreviewReportWidget::slotPriorPage()
{
    m_changingPage=true;
    if ((!m_reportPages.isEmpty())&&(m_currentPage>1)){
        m_currentPage--;
        ui->graphicsView->ensureVisible(
                    calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
        );
        emit pageChanged(m_currentPage);
    }
    m_changingPage=false;
}

void PreviewReportWidget::slotNextPage()
{
    m_changingPage=true;
    if ((!m_reportPages.isEmpty())&&(m_reportPages.count()>(m_currentPage))){
        m_currentPage++;
        ui->graphicsView->ensureVisible(
                    calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
        );
        emit pageChanged(m_currentPage);
    }
    m_changingPage=false;
}

void PreviewReportWidget::slotLastPage()
{
    m_changingPage=true;
    if ((!m_reportPages.isEmpty())&&(m_reportPages.count()>(m_currentPage))){
        m_currentPage=m_reportPages.count();
        ui->graphicsView->ensureVisible(
                    calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
        );
        emit pageChanged(m_currentPage);
    }
    m_changingPage=false;
}

void PreviewReportWidget::slotPrint()
{
    QPrinter printer(QPrinter::HighResolution);
    QPrintDialog dialog(&printer,QApplication::activeWindow());
    if (dialog.exec()==QDialog::Accepted){
        if (!m_reportPages.isEmpty())
            ReportEnginePrivate::printReport(
                m_reportPages,
                printer,
                PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage())
            );
        /*
        else ReportEnginePrivate::printReport(m_reader,printer);
        */
        foreach(PageItemDesignIntf::Ptr pageItem, m_reportPages){
            m_previewPage->reactivatePageItem(pageItem);
        }

    }
}

void PreviewReportWidget::slotPrintToPDF()
{
    QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" );
       //qDebug()<<fileName;
        if (!fileName.isEmpty()){
            QPrinter printer;
            printer.setOutputFileName(fileName);
            printer.setOutputFormat(QPrinter::PdfFormat);

            if (!m_reportPages.isEmpty()){
                ReportEnginePrivate::printReport(m_reportPages,printer,PrintRange());
            }
            /*
            else {
                ReportEnginePrivate::printReport(m_reader,printer);
            }
            */
            foreach(PageItemDesignIntf::Ptr pageItem, m_reportPages){
                m_previewPage->reactivatePageItem(pageItem);
            }
        }

}

void PreviewReportWidget::slotPageNavigatorChanged(int value)
{
    if (m_changingPage) return;
    m_changingPage = true;
    if ((!m_reportPages.isEmpty())&&(m_reportPages.count() >= value) && value>0){
        m_currentPage = value;
        //m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
        ui->graphicsView->ensureVisible(
                    calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
        );
    }
    m_changingPage=false;
}

void PreviewReportWidget::slotSliderMoved(int value)
{
    if (ui->graphicsView->verticalScrollBar()->minimum()==value){
        m_currentPage = 1;
    } else if (ui->graphicsView->verticalScrollBar()->maximum()==value){
        m_currentPage = m_reportPages.count();
    }

    if (!pageIsVisible(m_reportPages.at(m_currentPage-1))){
        if (value>m_priorScrolValue){
            m_currentPage++;
        } else {
            m_currentPage--;
        }
    }

    m_changingPage = true;
    emit pageChanged(m_currentPage);
    m_changingPage = false;
    m_priorScrolValue = value;

}

QRectF PreviewReportWidget::calcPageShift(PageItemDesignIntf::Ptr page)
{
    qreal pageHeight = page->mapToScene(page->boundingRect()).boundingRect().height();
    qreal viewHeight = ui->graphicsView->mapToScene(
                0,ui->graphicsView->viewport()->height()
                ).y()-ui->graphicsView->mapToScene(0,0).y();
    viewHeight = (pageHeight<viewHeight)?pageHeight:viewHeight;
    QRectF pageStartPos =  m_reportPages.at(m_currentPage-1)->mapRectToScene(
                m_reportPages.at(m_currentPage-1)->rect()
                );
    return QRectF(0,pageStartPos.y(),0,viewHeight);

}

bool PreviewReportWidget::pageIsVisible(PageItemDesignIntf::Ptr page)
{
    return page->mapToScene(page->rect()).boundingRect().intersects(
                ui->graphicsView->mapToScene(ui->graphicsView->viewport()->geometry()).boundingRect()
                );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef LRPREVIEWREPORTWIDGET_H
#define LRPREVIEWREPORTWIDGET_H

#include <QWidget>
#include "lrreportrender.h"

namespace Ui {
class PreviewReportWidget;
}
using namespace LimeReport;
class LIMEREPORT_EXPORT PreviewReportWidget : public QWidget
{
    Q_OBJECT

public:
    explicit PreviewReportWidget(ReportEnginePrivate *report, QWidget *parent=0);
    ~PreviewReportWidget();
    void actualiza();

public slots:
    void slotZoomIn();
    void slotZoomOut();

    void slotFirstPage();
    void slotPriorPage();
    void slotNextPage();
    void slotLastPage();

    void slotPrint();
    void slotPrintToPDF();
    void slotPageNavigatorChanged(int value);
private slots:
    void slotSliderMoved(int value);
    QRectF calcPageShift(PageItemDesignIntf::Ptr page);
private:
    bool pageIsVisible(PageItemDesignIntf::Ptr page);
private:
    Ui::PreviewReportWidget *ui;
    ReportEnginePrivate *m_report;
    PageDesignIntf* m_previewPage;
    ReportPages m_reportPages;
    bool m_changingPage;
    int m_currentPage;
    int m_priorScrolValue;

signals:
    void pageChanged(int page);
};

#endif // LRPREVIEWREPORTWIDGET_H
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Format number 99.999.999
« Reply #5 on: March 08, 2016, 02:52:22 pm »
Thanks