📄 ncreportdesignerresourcehandler.cpp
字号:
/*************************************************************************** * Copyright (C) 2006 by Norbert Szabo * * nszabo@helta.hu * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/#include "ncreportdesignerresourcehandler.h"#include "ncreportdesignerwidget.h"#include "ncreportdesignerwidgetfactory.h"#include "ncreportdesignerdesignarea.h"#include "ncreportdesignerdocument.h"#include "measurement.h"#include "globals.h"#include <qdom.h>#include <qwidgetlist.h>#include <qmessagebox.h>#include <qlabel.h>#include <qtextcodec.h>#include <qdatetime.h>#include <qobjectlist.h>#include <qregexp.h>#ifdef Q_WS_WIN#define TRIM_DEFAULT_TEXTWIDTH 1#define TRIM_DEFAULT_TEXTHEIGHT 0#else#define TRIM_DEFAULT_TEXTWIDTH 7#define TRIM_DEFAULT_TEXTHEIGHT 1#endif#define CRLF "\r\n"//-------------------------------// NCReportDesignerResourceHandler//-------------------------------NCReportDesignerResourceHandler::NCReportDesignerResourceHandler(){ designArea = 0; pasteOffset = 0;}NCReportDesignerResourceHandler::~NCReportDesignerResourceHandler(){}void NCReportDesignerResourceHandler::setDesignArea( NCReportDesignerDesignArea* da ){ designArea = da;}void NCReportDesignerResourceHandler::setSection( NCReportDesignerSection * se ){ section = se;}bool NCReportDesignerResourceHandler::load( QIODevice *file ){ QDomDocument doc; loadErrorMsg = QString::null; errorline =0; errorcol =0;#ifdef REPORTDESIGNER_DEBUG QTime t; t.start();#endif //QTextStream s( file ); //QString content = s.read(); //removeXMLComments( content ); //if ( !doc.setContent( content, &loadErrorMsg, &errorline, &errorcol ) ) { if ( !doc.setContent( file, &loadErrorMsg, &errorline, &errorcol ) ) { loadErrorMsg = QObject::tr("Parse error in line: %1 column: %2 ").arg(errorline).arg(errorcol)+loadErrorMsg; file->close(); return FALSE; } file->close();#ifdef REPORTDESIGNER_DEBUG qDebug("File parse time elapsed: %i", t.elapsed() );#endif //uiFileVersion = doc.firstChild().toElement().attribute("version"); QDomElement report = doc.documentElement(); // root element loadReportOptions( report ); //qApp->processEvents(); QDomNode node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "queries" ) { QDomElement queries = node.toElement(); loadQueries( queries ); break; } node = node.nextSibling(); }#ifdef REPORTDESIGNER_DEBUG qDebug("Load queries time: %i", t.elapsed() );#endif //qApp->processEvents(); node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "variables" ) { QDomElement variables = node.toElement(); loadVariables( variables ); break; } node = node.nextSibling(); }#ifdef REPORTDESIGNER_DEBUG qDebug("Load variables time: %i", t.elapsed() );#endif //qApp->processEvents(); node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "pageHeader" ) { QDomElement pageheader = node.toElement(); loadPageHeader( pageheader ); break; } node = node.nextSibling(); }#ifdef REPORTDESIGNER_DEBUG qDebug("Load page header time: %i", t.elapsed() );#endif node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "detail" ) { QDomElement detail = node.toElement(); loadDetail( detail ); break; } node = node.nextSibling(); }#ifdef REPORTDESIGNER_DEBUG qDebug("Load detail time: %i", t.elapsed() );#endif node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "pageFooter" ) { QDomElement pagefooter = node.toElement(); loadPageFooter( pagefooter ); break; } node = node.nextSibling(); }#ifdef REPORTDESIGNER_DEBUG qDebug("Load page footer time: %i", t.elapsed() );#endif node = report.firstChild(); while ( !node.isNull() ) { if ( node.isElement() && node.nodeName() == "groups" ) { QDomElement groups = node.toElement(); loadGroups( groups ); break; } node = node.nextSibling(); } //doc.firstChild().toElement().firstChild().toElement(); #ifdef REPORTDESIGNER_DEBUG qDebug("Total load time elapsed: %i", t.elapsed() );#endif return TRUE;}QString NCReportDesignerResourceHandler::lastLoadError( ){ return loadErrorMsg;}bool NCReportDesignerResourceHandler::loadReportOptions( QDomElement & e ){ if ( e.hasAttribute("name") ) document->po.reportName = e.attribute("name"); if ( e.hasAttribute("pageSize") ) document->po.pageSize = e.attribute("pageSize"); if ( e.hasAttribute("orientation") ) { document->po.orient = ( e.attribute("orientation")=="L" ? ReportPageOptions::Landscape : ReportPageOptions::Portrait);/* if ( e.attribute("orientation")=="P" ) document->po.orient = ReportPageOptions::Portrait; else if ( e.attribute("orientation")=="L" ) document->po.orient = ReportPageOptions::Landscape; else document->po.orient = ReportPageOptions::Portrait;*/ } if ( e.hasAttribute("pageWidth") ) document->po.pageWidth = e.attribute("pageWidth").toDouble(); if ( e.hasAttribute("pageHeight") ) document->po.pageHeight = e.attribute("pageHeight").toDouble(); if ( e.hasAttribute("printerMode") ) document->po.printerMode = e.attribute("printerMode"); if ( e.hasAttribute("topMargin") ) document->po.topMargin = e.attribute("topMargin").toDouble(); if ( e.hasAttribute("bottomMargin") ) document->po.bottomMargin = e.attribute("bottomMargin").toDouble(); if ( e.hasAttribute("leftMargin") ) document->po.leftMargin = e.attribute("leftMargin").toDouble(); if ( e.hasAttribute("rightMargin") ) document->po.rightMargin = e.attribute("rightMargin").toDouble(); if ( e.hasAttribute("defaultFontName") ) document->po.defaultFontName = e.attribute("defaultFontName"); if ( e.hasAttribute("defaultFontSize") ) document->po.defaultFontSize = e.attribute("defaultFontSize").toInt(); if ( e.hasAttribute("backColor") ) document->po.backColor = e.attribute("backColor"); if ( e.hasAttribute("masterAlias") ) document->po.masterAlias = e.attribute("masterAlias"); if ( e.hasAttribute("encoding") ) document->po.encoding = e.attribute("encoding"); if ( e.hasAttribute("dataSource") ) document->po.dataSource = ( e.attribute("dataSource").upper()=="TEXT" ? ReportPageOptions::Textfile : ReportPageOptions::Database ); if ( e.hasAttribute("resourceTextFile") ) document->po.resourceTextFile = e.attribute("resourceTextFile"); if ( e.hasAttribute("textDataDelimiter") ) document->po.textDataDelimiter = e.attribute("textDataDelimiter"); if ( e.hasAttribute("textRowFilterRegExp") ) document->po.rowFilterRegExp = e.attribute("textRowFilterRegExp"); return TRUE;}bool NCReportDesignerResourceHandler::loadQueries( QDomElement & e ){ QDomNode n = e.firstChild(); QDomElement de; while ( !n.isNull() ) { if ( n.isElement() && n.nodeName() == "query" ) { de = n.toElement(); ReportQuery q( de.attribute("alias"), de.text() ); document->addQuery( q ); } n = n.nextSibling(); } return TRUE;}bool NCReportDesignerResourceHandler::loadVariables( QDomElement & e ){ QDomNode n = e.firstChild(); QDomElement de; while ( !n.isNull() ) { if ( n.isElement() && n.nodeName() == "variable" ) { de = n.toElement(); ReportVariable v( de.attribute("name"), de.attribute("type"), de.attribute("funcType") ); v.field = de.text(); document->addVariable( v ); } n = n.nextSibling(); } return TRUE;}bool NCReportDesignerResourceHandler::loadPageHeader( QDomElement & e ){ NCReportDesignerSection *s = document->addPageHeader(); setSection( s ); setDesignArea( s->designArea() ); document->setPageSize( s ); //s->setWidth( 210.0 ); s->setHeight( e.attribute("height").toDouble() ); return loadSectionWidgets( e );}bool NCReportDesignerResourceHandler::loadPageFooter( QDomElement & e ){ NCReportDesignerSection *s = document->addPageFooter(); setSection( s ); setDesignArea( s->designArea() ); document->setPageSize( s ); //s->setWidth( 210.0 ); s->setHeight( e.attribute("height").toDouble() ); return loadSectionWidgets( e );}bool NCReportDesignerResourceHandler::loadDetail( QDomElement & e ){ NCReportDesignerSection *s = document->addDetail(); setSection( s ); setDesignArea( s->designArea() ); document->setPageSize( s ); //s->setWidth( 210.0 ); s->setHeight( e.attribute("height").toDouble() ); return loadSectionWidgets( e );}bool NCReportDesignerResourceHandler::loadGroups( QDomElement & e ){ QDomNode n = e.firstChild(); QDomElement gr; bool ok = TRUE; while ( !n.isNull() ) { if ( n.isElement() && n.nodeName() == "group" ) { gr = n.toElement(); ReportGroup group( gr.attribute("name"), gr.attribute("groupExpression"), gr.attribute("resetVariables") ); document->addGroup( group ); // create whole group QDomNode n2 = gr.firstChild(); while ( !n2.isNull() ) { if ( n2.isElement() && n2.nodeName() == "groupHeader" ) { QDomElement e0 = n2.toElement(); // HEADER SETUP setSection( group.header ); setDesignArea( group.header->designArea() ); document->setPageSize( group.header ); group.header->setHeight( e0.attribute("height").toDouble() ); ok = loadSectionWidgets( e0 ); } if ( ok && n2.isElement() && n2.nodeName() == "groupFooter" ) { QDomElement e0 = n2.toElement(); // FOOTER SETUP setSection( group.footer ); setDesignArea( group.footer->designArea() ); document->setPageSize( group.footer ); group.footer->setHeight( e0.attribute("height").toDouble() ); ok = loadSectionWidgets( e0 ); } n2 = n2.nextSibling(); } } n = n.nextSibling(); } return ok;}bool NCReportDesignerResourceHandler::loadSectionWidgets( QDomElement & e ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -