📄 ncreportdesignerresourcehandler.cpp
字号:
pasteOffset = 0; if ( !designArea ) return FALSE; QDomNode n = e.firstChild(); QDomElement widgetelement; // = e.firstChild().toElement(); #ifdef REPORTDESIGNER_DEBUG QTime t; t.start();#endif while ( !n.isNull() ) { if ( n.nodeType() == QDomNode::ElementNode ) { widgetelement = n.toElement(); QWidget *w = NCReportDesignerWidgetFactory::create( widgetelement, designArea, 0, FALSE );#ifdef REPORTDESIGNER_DEBUG qDebug("NCReportDesignerWidgetFactory::create() time: %i", t.elapsed() );#endif if ( w ) { NCReportDesignerWidget *dw =0; if ( ::qt_cast<NCReportDesignerWidget*>(w) ) dw = (NCReportDesignerWidget*)w; #ifdef REPORTDESIGNER_DEBUG qDebug("loadWidget before time: %i", t.elapsed() );#endif loadWidget( widgetelement, dw ); w->show(); designArea->widgets()->insert( w, w );#ifdef REPORTDESIGNER_DEBUG qDebug("loadWidget after time: %i", t.elapsed() );#endif } } n = n.nextSibling(); //widgetelement = widgetelement.nextSibling().toElement(); }#ifdef REPORTDESIGNER_DEBUG qDebug("loadSectionWidgets time: %i", t.elapsed() );#endif return TRUE;}QString NCReportDesignerResourceHandler::copy( ){ if ( !designArea ) return QString::null; copying = TRUE; QString s; QTextOStream ts( &s ); ts << "<NCREPORT-SELECTION>" << CRLF; QWidgetList widgets = designArea->selectedWidgets(); QWidgetList tmp( widgets ); for ( QWidget *w = widgets.first(); w; w = widgets.next() ) { if ( !::qt_cast<NCReportDesignerWidget*>(w) ) break; NCReportDesignerWidget *dw = ::qt_cast<NCReportDesignerWidget*>(w); saveWidget( dw, ts, 1 ); } ts << "</NCREPORT-SELECTION>" << CRLF; return s;}bool NCReportDesignerResourceHandler::save( const QString & ){ return true;}bool NCReportDesignerResourceHandler::save( QIODevice *f ){ QTextStream t( f ); t.setCodec( QTextCodec::codecForName(document->po.encoding) ); t << "<?xml version=\"1.0\" encoding=\"" << document->po.encoding << "\"?>" << CRLF; t << "<NCReport" << CRLF; t << makeIndent(1) << "name=\"" << document->po.reportName << "\"" << CRLF; t << makeIndent(1) << "dataSource=\"" << (document->po.dataSource == ReportPageOptions::Database ? "DB" : "text") << "\"" << CRLF; if ( document->po.dataSource == ReportPageOptions::Textfile ) { t << makeIndent(1) << "resourceTextFile=\"" << document->po.resourceTextFile << "\"" << CRLF; t << makeIndent(1) << "textDataDelimiter=\"" << document->po.textDataDelimiter << "\"" << CRLF; t << makeIndent(1) << "textRowFilterRegExp=\"" << document->po.rowFilterRegExp << "\"" << CRLF; } t << makeIndent(1) << "encoding=\"" << document->po.encoding << "\"" << CRLF; t << makeIndent(1) << "pageSize=\"" << document->po.pageSize << "\"" << CRLF; t << makeIndent(1) << "orientation=\"" << (document->po.orient == ReportPageOptions::Portrait ? 'P' : 'L') << "\"" << CRLF; t << makeIndent(1) << "printerMode=\"" << document->po.printerMode << "\"" << CRLF; //t << makeIndent(1) << "columnCount=\"" << document->name << "\"" << CRLF; t << makeIndent(1) << "topMargin=\"" << document->po.topMargin << "\"" << CRLF; t << makeIndent(1) << "bottomMargin=\"" << document->po.bottomMargin << "\"" << CRLF; t << makeIndent(1) << "leftMargin=\"" << document->po.leftMargin << "\"" << CRLF; t << makeIndent(1) << "rightMargin=\"" << document->po.rightMargin << "\"" << CRLF; t << makeIndent(1) << "defaultFontName=\"" << document->po.defaultFontName << "\"" << CRLF; t << makeIndent(1) << "defaultFontSize=\"" << document->po.defaultFontSize << "\"" << CRLF; t << makeIndent(1) << "backcolor=\"" << document->po.backColor << "\"" << CRLF; t << makeIndent(1) << "masterAlias=\"" << document->po.masterAlias << "\"" << CRLF; t << makeIndent(1) << ">" << CRLF; t << makeIndent(1) << CRLF; t << "<queries>" << CRLF; { QMap<QString,ReportQuery>::ConstIterator it; for ( it = document->queries.begin(); it != document->queries.end(); ++it ) { t << makeIndent(1) << "<query alias=\"" << it.data().alias << "\">" << CRLF; t << makeIndent(2) << entitize(it.data().queryString, FALSE) << CRLF; t << makeIndent(1) << "</query>" << CRLF; } } t << "</queries>" << CRLF; t << "<variables>" << CRLF; { QMap<QString,ReportVariable>::ConstIterator it; for ( it = document->variables.begin(); it != document->variables.end(); ++it ) { t << makeIndent(1) << "<variable name=\"" << it.data().name << "\""; t << " type=\"" << it.data().type << "\""; t << " funcType=\"" << it.data().funcType << "\""; t << ">"; t << it.data().field; t << "</variable>" << CRLF; } } t << "</variables>" << CRLF; //-------------------------------- // page header //-------------------------------- NCReportDesignerSection *s = document->sections["pheader"]; t << "<pageHeader"; t << " height=\"" << m->pixelToMeasure( s->designArea()->height() ) << "\""; t << ">" << CRLF; saveWidgetsOfSection( s, t, 1 ); t << "</pageHeader>" << CRLF; //-------------------------------- // page footer //-------------------------------- s = document->sections["pfooter"]; t << "<pageFooter"; t << " height=\"" << m->pixelToMeasure( s->designArea()->height() ) << "\""; t << ">" << CRLF; saveWidgetsOfSection( s, t, 1 ); t << "</pageFooter>" << CRLF; //-------------------------------- // groups //-------------------------------- t << "<groups>" << CRLF; { QMap<QString,ReportGroup>::ConstIterator it; for ( it = document->groups.begin(); it != document->groups.end(); ++it ) { //ReportGroup g = it.data(); t << makeIndent(1) << "<group name=\"" << it.data().name << "\""; t << " groupExpression=\"" << it.data().groupExpression << "\""; t << " resetVariables=\"" << it.data().resetVariables << "\""; t << ">" << CRLF; // ------ GROUP HEADER s = it.data().header; t << makeIndent(2) << "<groupHeader"; t << " height=\"" << m->pixelToMeasure( s->designArea()->height() ) << "\""; t << ">" << CRLF; saveWidgetsOfSection( s, t, 3 ); t << makeIndent(2) << "</groupHeader>" << CRLF; // ------ GROUP FOOTER s = it.data().footer; t << makeIndent(2) << "<groupFooter"; t << " height=\"" << m->pixelToMeasure( s->designArea()->height() ) << "\""; t << ">" << CRLF; saveWidgetsOfSection( s, t, 3 ); t << makeIndent(2) << "</groupFooter>" << CRLF; // -------------------- t << makeIndent(1) << "</group>" << CRLF; } } t << "</groups>" << CRLF; //-------------------------------- // detail //-------------------------------- s = document->sections["detail"]; t << "<detail"; t << " height=\"" << m->pixelToMeasure( s->designArea()->height() ) << "\""; t << ">" << CRLF; saveWidgetsOfSection( s, t, 1 ); t << "</detail>" << CRLF; // FOOTER t << "</NCReport>" << CRLF; return true;}void NCReportDesignerResourceHandler::saveWidgetsOfSection( NCReportDesignerSection *s, QTextStream &ts, int indent ){ QObjectList *l = s->designArea()->queryList( "QWidget" ); //QObjectList *l = s->designArea()->queryList( "NCReportDesignerWidget" ); if ( l ) { for ( QObject *o = l->first(); o; o = l->next() ) { //if ( ::qt_cast<QWidget*>(o) ) { if ( o->isA("QWidget") ) { NCReportDesignerWidget *dw = ::qt_cast<NCReportDesignerWidget*>(o); if ( ( (QWidget*)o )->isVisible() ) //if ( dw->isVisibleTo( s->designArea() ) ) saveWidget( dw, ts, indent ); } } delete l; }}void NCReportDesignerResourceHandler::saveElement( QObject * , QTextStream &, int ){/* if ( obj && obj->isWidgetType() && ( (QWidget*)obj )->isHidden() ) return; if ( !::qt_cast<NCReportDesignerWidget*>(obj) ) return;*/}void NCReportDesignerResourceHandler::paste( const QString &cb, QWidget *parent ){ if ( !designArea ) return; pasteOffset = designArea->grid().x(); //pasteOffset = 2; pasting = TRUE; QDomDocument doc; QString errorMsg; int errorLine; bool ok = doc.setContent( cb, TRUE, &errorMsg, &errorLine ); if ( !ok ) { QMessageBox::warning( 0, QObject::tr("Designer error"), QObject::tr("Paste error occured. Cannot parse copied information.")+'\n' +errorMsg ); return; } QDomElement widgetelement = doc.firstChild().toElement().firstChild().toElement(); QWidgetList widgets; designArea->clearSelection( FALSE ); /* <rectangle posX="0" posY="14" height="6" lineWidth="1" roundValue="8" lineColor="#0000FF"></rectangle> <label fontSize="8" posX="1" posY="15" alignmentH="left" forecolor="#0000FF">No.</label> <label fontSize="8" posX="7" posY="15" alignmentH="left" forecolor="#0000FF">Product no.</label> <label fontSize="8" posX="31" posY="15" alignmentH="left" forecolor="#0000FF">Product name</label> <label fontSize="8" posX="101" posY="15" alignmentH="right" width="19" forecolor="#0000FF">List price</label> <label fontSize="8" posX="121" posY="15" alignmentH="right" width="19" forecolor="#0000FF">Price II.</label> <label fontSize="8" posX="141" posY="15" alignmentH="right" width="19" forecolor="#0000FF">Price III.</label> <label fontSize="8" posX="161" posY="15" alignmentH="right" width="19" forecolor="#0000FF">Price IV.</label> */ //designArea->setPropertyShowingBlocked( TRUE ); while ( !widgetelement.isNull() ) { //QWidget *w = (QWidget*)createObject( widgetelement, parent, 0 ); QWidget *w = NCReportDesignerWidgetFactory::create( widgetelement, parent, 0, FALSE ); if ( !w ) continue; NCReportDesignerWidget *dw =0; if ( ::qt_cast<NCReportDesignerWidget*>(w) ) dw = (NCReportDesignerWidget*)w; loadWidget( widgetelement, dw ); widgets.append( w ); /* int x = w->x() + designArea->grid().x(); int y = w->y() + designArea->grid().y(); if ( w->x() + dw->width() > parent->width() ) x = QMAX( 0, parent->width() - w->width() ); if ( w->y() + w->height() > parent->height() ) y = QMAX( 0, parent->height() - w->height() ); if ( x != w->x() || y != w->y() ) w->move( x, y );*/ widgetelement = widgetelement.nextSibling().toElement(); } //designArea->setPropertyShowingBlocked( FALSE ); //designArea->emitShowProperties(); cmd_PasteCommand *cmd = new cmd_PasteCommand( QObject::tr( "Paste" ), designArea, widgets ); designArea->commandHistory()->addCommand( cmd ); cmd->execute();}void NCReportDesignerResourceHandler::loadWidget( QDomElement & e, NCReportDesignerWidget * w ){ double _fromX=0,_toX =0,_fromY=0,_toY=0; if ( e.hasAttribute("ftype") ) w->p.ftype = e.attribute("ftype"); if ( e.hasAttribute("type") ) w->p.type = e.attribute("type"); if ( e.hasAttribute("printWhen") ) w->p.printWhen = e.attribute("printWhen"); if ( e.hasAttribute("embedString") ) w->p.embedString = e.attribute("embedString"); if ( e.hasAttribute("callFunction") ) w->p.callFunction = e.attribute("callFunction"); if ( e.hasAttribute("lookupClass") ) w->p.lookupClass = e.attribute("lookupClass"); if ( e.hasAttribute("numDigitNo") ) w->p.numDigitNo = e.attribute("numDigitNo").toInt(); if ( e.hasAttribute("numSeparation") ) w->p.numSeparation = (e.attribute("numSeparation")=="true"); if ( e.hasAttribute("numSeparator") ) w->p.numSeparator = e.attribute("numSeparator").at(0).latin1(); if ( e.hasAttribute("numDigitPoint") ) w->p.numDigitPoint = e.attribute("numDigitPoint").at(0).latin1(); if ( e.hasAttribute("numBlankIfZero") ) w->p.numBlankIfZero = (e.attribute("numBlankIfZero")=="true"); if ( e.hasAttribute("numFormat") ) w->p.numFormat = e.attribute("numFormat"); if ( e.hasAttribute("dateFormat") ) w->p.dateFormat = e.attribute("dateFormat"); if ( e.hasAttribute("posX") ) w->p._posX = e.attribute("posX").toDouble(); if ( e.hasAttribute("posY") ) w->p._posY = e.attribute("posY").toDouble(); if ( e.hasAttribute("fromX") ) _fromX = e.attribute("fromX").toDouble(); if ( e.hasAttribute("fromY") ) _fromY = e.attribute("fromY").toDouble(); if ( e.hasAttribute("toX") ) _toX = e.attribute("toX").toDouble(); if ( e.hasAttribute("toY") ) _toY = e.attribute("toY").toDouble(); if ( e.hasAttribute("width") ) w->p._width = e.attribute("width").toDouble(); if ( e.hasAttribute("height") ) w->p._height = e.attribute("height").toDouble(); if ( e.hasAttribute("fontName") ) w->p.fontName = e.attribute("fontName"); if ( e.hasAttribute("fontSize") ) w->p.fontSize = e.attribute("fontSize").toInt(); if ( e.hasAttribute("fontWeight") ) { QFont::Weight we = QFont::Normal; QString att = e.attribute("fontWeight"); if (att == "light") we = QFont::Light; else if (att == "normal") we = QFont::Normal; else if (att == "demibold") we = QFont::DemiBold; else if (att == "bold") we = QFont::Bold; else if (att == "black") we = QFont::Black;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -