void tGraph::draw(QPainter & paint) { //QPainter paint(this); paint.save(); int gx1 = hPadding() + _rect.x(); int gy1 = vPadding() + _rect.y(); int gx2 = _rect.x() + width() - hPadding(); int gy2 = _rect.y() + height() - vPadding(); //paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1); QFontMetrics fm(font()); //QRect brect; // get the dimensions of the title label and then draw it if(title().length() > 0) { fm = QFontMetrics(titleFont()); //brect = fm.boundingRect(title()); paint.setFont(titleFont()); paint.drawText(gx1, gy1, gx2 - gx1, fm.height(), titleAlignment(), title()); gy1 += fm.height(); } // we need to do some drawing that depends on some other elements having // already been placed... since those require that these have already been // placed we will just save the old value of gy2 and then calculate the // value that we should have after the other code runs without actually // drawing anything right now int gy2_old = gy2; if(dataLabel().length() > 0) { fm = QFontMetrics(dataLabelFont()); gy2 -= fm.height(); } fm = QFontMetrics(dataFont()); QMapIterator<int, GReference> dlit = _data.begin(); double tlh = 0.0; for(dlit = _data.begin(); dlit != _data.end(); ++dlit) { tlh = QMAX(sin45deg * fm.width(dlit.data().first), tlh); } // don't change this variable as we use it later int th = (tlh == 0.0 ? 0 : (int)(tlh + (fm.height() * sin45deg)) + 2); gy2 -= th; // get the dimensions of the value label then draw it if(valueLabel().length() > 0) { fm = QFontMetrics(valueLabelFont()); //brect = fm.boundingRect(valueLabel()); paint.setFont(valueLabelFont()); paint.save(); paint.rotate(-90); paint.drawText(-gy2, gx1, gy2 - gy1, fm.height(), valueLabelAlignment(), valueLabel()); paint.restore(); gx1 += fm.height(); } fm = QFontMetrics(valueFont()); QString min_str = QString().sprintf("%-.0f",minValue()); QString org_str = ( minValue() == 0.0 ? QString::null : "0" ); QString max_str = QString().sprintf("%-.0f",maxValue()); int width = QMAX(fm.width(min_str), fm.width(max_str)); if(org_str.length() > 0) width = QMAX(width, fm.width(org_str)); gx1 += width; int gy_max = gy1; int gy_min = gy2 - 1; int gy_org = gy_min; paint.setFont(valueFont()); int tfa = Qt::AlignTop | Qt::AlignRight; paint.drawText(gx1 - fm.width(min_str), gy_min, fm.width(min_str), fm.height(), tfa, min_str); paint.drawLine(gx1 - 3, gy_min, gx1 + 2, gy_min); paint.drawText(gx1 - fm.width(max_str), gy_max, fm.width(max_str), fm.height(), tfa, max_str); paint.drawLine(gx1 - 3, gy_max, gx1 + 2, gy_max); int gheight = gy2 - gy1; double grng = maxValue() - minValue(); if(org_str.length() > 0) { double perc = (0 - minValue()) / grng; gy_org = gy2 - (int)(perc * (double)gheight); paint.drawText(gx1 - fm.width(org_str), gy_org, fm.width(org_str), fm.height(), tfa, org_str); paint.drawLine(gx1 - 3, gy_org, gx1 + 2, gy_org); } gx1 += 3; // put the old value back so all the code to come draw correctly! gy2 = gy2_old; // get the dimensions of the data label then draw it if(dataLabel().length() > 0) { fm = QFontMetrics(dataLabelFont()); //brect = fm.boundingRect(dataLabel()); paint.setFont(dataLabelFont()); gy2 -= fm.height(); paint.drawText(gx1, gy2, gx2 - gx1, fm.height(), dataLabelAlignment(), dataLabel()); } gy2 -= th; int ref_cnt = _data.count(); int gwidth = gx2 - gx1; gheight = gy2 - gy1; if(ref_cnt > 0) { paint.save(); fm = QFontMetrics(dataFont()); paint.setFont(dataFont()); int refwidth = QMAX(1, gwidth / ref_cnt); int buf = (int)(refwidth / 5); int buf2 = buf * 2; QMapIterator<int, GReference> rit; int pos = gx1 + (int)((gwidth - (refwidth * ref_cnt)) / 2); int bar_height; int fmheight = fm.height(); int fmheight_div_2 = fmheight / 2; int refwidth_div_2 = refwidth / 2; int label_offset = (int)(fmheight_div_2 * cos45deg); int last_label_at = -1000; QMap<int, double> last_map; QMap<int, double> this_map; for(rit = _data.begin(); rit != _data.end(); ++rit ) { GReference ref = rit.data(); QString label = ref.first; if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) { last_label_at = pos + refwidth_div_2; int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg)); int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg)); int fmwidth = fm.width(label); paint.save(); paint.rotate(-45); paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, Qt::AlignRight | Qt::AlignTop, label); paint.restore(); } QMapIterator<int, double> sit; paint.save(); if(drawBars() == TRUE) { TSetValue tval; QMap<double, TSetValue> sort_map; for(sit = ref.second.begin(); sit != ref.second.end(); ++sit ) { if(sit.data() != 0.0 && _setStyle[sit.key()].bar == TRUE) { tval.first = sit.key(); tval.second = sit.data(); sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval; } } QMapIterator<double, TSetValue> it; for(it = sort_map.begin(); it != sort_map.end(); ++it) { tval = it.data(); if(tval.second != 0.0) { if(tval.second < 0) { bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min)); } else { bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max)); } paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first)); } } } if(drawLines() == TRUE) { this_map.clear(); for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) { if(_setStyle[sit.key()].line == TRUE) { this_map[sit.key()] = sit.data(); if(last_map.contains(sit.key())) { paint.setPen(getSetColor(sit.key())); double old_val = last_map[sit.key()]; double new_val = sit.data(); int ly1; if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min)); else ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max)); ly1 = gy_org - ly1; int lx1 = pos - refwidth_div_2; int ly2; if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min)); else ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max)); ly2 = gy_org - ly2; int lx2 = pos + refwidth_div_2; paint.drawLine(lx1, ly1, lx2, ly2); } } } last_map = this_map; } if(drawPoints() == TRUE) { for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) { if(_setStyle[sit.key()].point == TRUE) { paint.setBrush(getSetColor(sit.key())); paint.setPen(QColor(0,0,0)); int ly1; if(sit.data() < 0.0) ly1 = (int)((sit.data() / minValue()) * (gy_org - gy_min)); else ly1 = (int)((sit.data() / maxValue()) * (gy_org - gy_max)); ly1 = gy_org - ly1; int lx1 = pos + refwidth_div_2; paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5); } } } paint.restore(); pos += refwidth; } paint.restore(); } paint.drawLine(gx1, gy_org, gx2 - 1, gy_org); paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1); // Now that we are done return the paint device back to the state // it was when we started to mess with it paint.restore(); }
void BpDocument::composeTable3( int vid, EqVar *rowVar, EqVar *colVar ) { // START THE STANDARD PREAMBLE USED BY ALL TABLE COMPOSITION FUNCTIONS. // WIN98 requires that we actually create a font here and use it for // font metrics rather than using the widget's font. QFont subTitleFont( property()->string( "tableSubtitleFontFamily" ), property()->integer( "tableSubtitleFontSize" ) ); QPen subTitlePen( property()->color( "tableSubtitleFontColor" ) ); QFontMetrics subTitleMetrics( subTitleFont ); QFont textFont( property()->string( "tableTextFontFamily" ), property()->integer( "tableTextFontSize" ) ); QPen textPen( property()->color( "tableTextFontColor" ) ); QFontMetrics textMetrics( textFont ); QFont titleFont( property()->string( "tableTitleFontFamily" ), property()->integer( "tableTitleFontSize" ) ); QPen titlePen( property()->color( "tableTitleFontColor" ) ); QFontMetrics titleMetrics( titleFont ); QFont valueFont( property()->string( "tableValueFontFamily" ), property()->integer( "tableValueFontSize" ) ); QPen valuePen( property()->color( "tableValueFontColor" ) ); QFontMetrics valueMetrics( valueFont ); bool doRowBg = property()->boolean( "tableRowBackgroundColorActive" ); QBrush rowBrush( property()->color( "tableRowBackgroundColor" ), Qt::SolidPattern ); QString text(""); // Store pixel resolution into local variables. double yppi = m_screenSize->m_yppi; double xppi = m_screenSize->m_xppi; double m_padWd = m_pageSize->m_padWd; // Determine the height of the various display fonts. double textHt, titleHt, valueHt, rowHt, x0, x1; textHt = ( textMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; titleHt = ( titleMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; valueHt = ( valueMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; rowHt = ( textHt > valueHt ) ? textHt : valueHt; // END THE STANDARD PREAMBLE USED BY ALL TABLE COMPOSITION FUNCTIONS. // Determine the number of rows we can display on a page. int rowsPerPage = (int) ( ( m_pageSize->m_bodyHt - 5. * titleHt - 4. * textHt ) / rowHt ); // Number of pages the table requires to accomodate all the rows. int pagesLong = 1 + (int) ( tableRows() / rowsPerPage ); // Arrays to hold the output values' column information. // Page on which the output value column appears. int *colPage = new int[ tableCols() ]; checkmem( __FILE__, __LINE__, colPage, "int colPage", tableCols() ); // Horizontal position of each output value column. double *colXPos = new double[ tableCols() ]; checkmem( __FILE__, __LINE__, colXPos, "double colXPos", tableCols() ); // Column header text. QString *colText = new QString[ tableCols() ]; checkmem( __FILE__, __LINE__, colText, "double colText", tableCols() ); // Prescription shading? bool doRx = property()->boolean( "tableShading" ); bool doBlank = property()->boolean( "tableShadingBlank" ); // Determine the row variable's (left-most) column width. int row, iid, cell; double len; QString qStr; // Start wide enough to hold the variable name and units. double rowWd = m_padWd + ( (double) headerWidth( rowVar, textMetrics ) / xppi ); // Enlarge it to hold the fattest row value. m_rowDecimals = 0; for ( row = 0; row < tableRows(); row++ ) { if ( rowVar->isDiscrete() ) { iid = (int) tableRow( row ); qStr = rowVar->m_itemList->itemName( iid ) + "MMM"; } else if ( rowVar->isContinuous() ) { // CDB DECIMALS MOD if ( false ) { qStr.sprintf( "%1.*fMMM", rowVar->m_displayDecimals, tableRow( row ) ); } else { // Start with 6 decimals for this row value int decimals = 6; qStr.sprintf( "%1.*f", decimals, tableRow( row ) ); // Remove all trailing zeros while ( qStr.endsWith( "0" ) ) { qStr = qStr.left( qStr.length()-1 ); decimals--; } // Update m_rowDecimals digits m_rowDecimals = ( decimals > m_rowDecimals ) ? decimals : m_rowDecimals; qStr.append( "MWM" ); } } len = (double) textMetrics.width( qStr ) / xppi; if ( len > rowWd ) { rowWd = len; } } // Find the fattest output value for this table variable. int col; int out = vid; EqVar *outVar = tableVar(vid); double colWd = 0; for ( row = 0; row < tableRows(); row++ ) { for ( col = 0; col < tableCols(); col++ ) { if ( outVar->isDiscrete() ) { iid = (int) tableVal( out ); qStr = outVar->m_itemList->itemName( iid ) + "WM"; } else if ( outVar->isContinuous() ) { qStr.sprintf( "%1.*fWM", outVar->m_displayDecimals, tableVal( out ) ); } len = (double) textMetrics.width( qStr ) / xppi; if ( len > colWd ) { colWd = len; } out += tableVars(); } // Next table column. } // Next table row. // Set the column header value text. m_colDecimals = 0; for ( col = 0; col < tableCols(); col++ ) { if ( colVar->isDiscrete() ) { iid = (int) tableCol( col ); colText[col] = colVar->m_itemList->itemName( iid ); } else if ( colVar->isContinuous() ) { // CDB DECIMALS MOD if ( false ) { colText[col].sprintf( " %1.*f", colVar->m_displayDecimals, tableCol( col ) ); } else { // Start with 6 decimals for this row value int decimals = 6; colText[col].sprintf( " %1.*f", decimals, tableCol( col ) ); // Remove all trailing zeros while ( colText[col].endsWith( "0" ) ) { colText[col] = colText[col].left( colText[col].length()-1 ); decimals--; } // Update Decimals digits m_colDecimals = ( decimals > m_colDecimals ) ? decimals : m_colDecimals; } } // Expand the column width to accomodate the header value text? len = (double) textMetrics.width( colText[col] ) / xppi; if ( len > colWd ) { colWd = len; } } // Next table column. // CDB DECIMALS MOD for ( col = 0; col < tableCols(); col++ ) { if ( colVar->isContinuous() ) { colText[col].sprintf( " %1.*f", m_colDecimals, tableCol( col ) ); } } // Add padding between each column. colWd += m_padWd; // Determine each column's position on each page. int pagesWide = 1; // Horizontal position of first column on the first page. double xpos = m_pageSize->m_bodyLeft + rowWd + 2. * m_padWd; for ( col = 0; col < tableCols(); col++ ) { // If past the right page edge, start a new page. if ( xpos + colWd > m_pageSize->m_bodyRight ) { // The table page width has just increased. pagesWide++; // This will be the first column on the new page. xpos = m_pageSize->m_bodyLeft + rowWd + 2. * m_padWd; } // Store the page and position of this output variable's column. colXPos[col] = xpos; colPage[col] = pagesWide; // Update the position pointer. xpos += ( 2. * m_padWd + colWd ); } // Determine the column title width (inches). double colTitleWd = textMetrics.width( *(colVar->m_label) ) / xppi; if ( ( textMetrics.width( colVar->m_displayUnits ) / xppi ) > colTitleWd ) { colTitleWd = textMetrics.width( colVar->m_displayUnits ) / xppi; } colTitleWd += ( 2. * m_padWd ); // Determine an offset shift to center each pageAcross. double *shift = new double[ pagesWide + 1 ]; checkmem( __FILE__, __LINE__, shift, "double shift", pagesWide + 1 ); for ( col = 0; col < tableCols(); col++ ) { // Table must be at least this wide. double minLeft = m_pageSize->m_bodyLeft + rowWd + 2. * m_padWd + colTitleWd; // Does it need to be wider to accomodate this column? if ( colXPos[col] + colWd > minLeft ) { minLeft = colXPos[col] + colWd; } // Just the last column of each page finally gets stored in shift[]. shift[colPage[col]] = 0.5 * ( m_pageSize->m_bodyRight - minLeft ); } // Start drawing the table. double yPos, s, bgLeft, bgRight, rightEdge, leftEdge; int i; // Loop for each page down. int thisPage = 1; for ( int pageDown = 1; pageDown <= pagesLong; pageDown++ ) { // Loop for each page across. for ( int pageAcross = 1; pageAcross <= pagesWide; pageAcross++, thisPage++ ) { // Table title indicates the table portion translate( text, "BpDocument:Table:PageOf", *(tableVar(vid)->m_label), QString( "%1" ).arg( thisPage ), QString( "%1" ).arg( pagesLong * pagesWide ) ); // Start a new page startNewPage( text, TocTable ); yPos = m_pageSize->m_marginTop + titleHt; // Draw a map of where we are. composePageMap( ( 2. * titleHt - 0.1 ), pagesLong, pagesWide, pagesLong, pagesWide, 1, 1, pageDown-1, pageAcross-1 ); // Display the table title::description m_composer->font( titleFont ); // use tableTitleFont m_composer->pen( titlePen ); // use tableTitleFontColor qStr = m_eqTree->m_eqCalc->docDescriptionStore().stripWhiteSpace(); m_composer->text( m_pageSize->m_marginLeft, yPos, // start at UL corner m_pageSize->m_bodyWd, titleHt,// width and height Qt::AlignVCenter|Qt::AlignHCenter, // center alignement qStr ); // display description yPos += titleHt; // Display the table title::variable m_composer->font( subTitleFont ); // use tableSubtitleFont m_composer->pen( subTitlePen ); // use tableSubtitleFontColor qStr = *(outVar->m_label); if ( outVar->isContinuous() ) { qStr = *(outVar->m_label) + " " + outVar->displayUnits(true); } m_composer->text( m_pageSize->m_marginLeft, yPos, // start at UL corner m_pageSize->m_bodyWd, titleHt,// width and height Qt::AlignVCenter|Qt::AlignHCenter, // center alignment qStr ); // table variable name yPos += titleHt; // Display the table title::portion //m_composer->text( // m_pageSize->m_marginLeft, yPos, // m_pageSize->m_bodyWd, titleHt, // Qt::AlignVCenter|Qt::AlignHCenter, // portion ); //yPos += titleHt; yPos += titleHt; // Everything else on this page is shifted s = shift[pageAcross]; // Determine left and right edges of the table. leftEdge = -1; for ( col = 0; col < tableCols(); col++ ) { if ( pageAcross == colPage[col] ) { rightEdge = colXPos[col] + colWd + s; if ( leftEdge < 0. ) { leftEdge = colXPos[col] + s; } } } // Must be at least wide enough to accomodate column header text. if ( rightEdge < leftEdge + colTitleWd ) { rightEdge = leftEdge + colTitleWd; } bgLeft = m_pageSize->m_marginLeft + s - m_padWd ; bgRight = rightEdge - leftEdge + rowWd + 4 * m_padWd ; // Display a colored row column header background? if ( doRowBg ) { m_composer->fill( bgLeft, yPos, bgRight, 3 * textHt, rowBrush ); } // Display the row column header0. m_composer->font( textFont ); // use tableTextFont m_composer->pen( textPen ); // use tableTextFontColor m_composer->text( m_pageSize->m_marginLeft + s, yPos, rowWd, textHt, Qt::AlignVCenter|Qt::AlignLeft, *(rowVar->m_hdr0) ); // Display the row column header1. m_composer->text( m_pageSize->m_marginLeft + s, yPos + textHt, rowWd, textHt, Qt::AlignVCenter|Qt::AlignLeft, *(rowVar->m_hdr1) ); // Display the row column units. m_composer->text( m_pageSize->m_marginLeft + s, yPos + 2. * textHt, rowWd, textHt, Qt::AlignVCenter|Qt::AlignLeft, rowVar->displayUnits() ); // Display the row column header underline // only if we are not coloring row backgrounds. int skipLines = 3; if ( ! doRowBg ) { m_composer->line( m_pageSize->m_marginLeft + s, yPos + 3.5 * textHt, m_pageSize->m_marginLeft + rowWd + s, yPos + 3.5 * textHt ); skipLines = 4; } // Display the output column headers. for ( col = 0; col < tableCols(); col++ ) { if ( pageAcross == colPage[col] ) { // Display the output column units. m_composer->text( colXPos[col] + s, yPos + 2. * textHt, colWd, textHt, Qt::AlignVCenter|Qt::AlignRight, colText[col] ); // Display the output column underline. if ( ! doRowBg ) { m_composer->line( colXPos[col] + s, yPos + 3.5 * textHt, colXPos[col] + colWd + s, yPos + 3.5 * textHt ); } } } // Display a centered column variable name and units header. m_composer->text( leftEdge, yPos, ( rightEdge - leftEdge ), textHt, Qt::AlignVCenter|Qt::AlignHCenter, *(colVar->m_label) ); if ( colVar->isContinuous() ) { m_composer->text( leftEdge, yPos + textHt, ( rightEdge - leftEdge ), textHt, Qt::AlignVCenter|Qt::AlignHCenter, colVar->displayUnits() ); } // If there are previous columns, display a visual cue. if ( pageAcross > 1 ) { for ( i = 0; i < 3; i++ ) { m_composer->text( 0, ( yPos + i * textHt ), ( m_pageSize->m_marginLeft + s - m_padWd ), textHt, Qt::AlignVCenter|Qt::AlignRight, "<" ); } } // If there are subsequent column pages, display a visual clue. if ( pageAcross < pagesWide ) { for ( i = 0; i < 3; i++ ) { m_composer->text( ( rightEdge + m_padWd ), ( yPos + i * textHt ), ( m_pageSize->m_pageWd - rightEdge ), textHt, Qt::AlignVCenter|Qt::AlignLeft, ">" ); } } // Set vertical start of rows. yPos += skipLines * textHt; // Determine the rows range to display on this page. int rowFrom = ( pageDown - 1 ) * rowsPerPage; int rowThru = pageDown * rowsPerPage - 1; if ( rowThru >= tableRows() ) { rowThru = tableRows() - 1; } // Determine the columns range to display on this page. int colFrom = -1; int colThru = 0; for ( col = 0; col < tableCols(); col++ ) { if ( colPage[col] == pageAcross ) { if ( colFrom == -1 ) { colFrom = col; } colThru = col; } } // Loop for each row on this page. bool doThisRowBg = false; for ( row = rowFrom; row <= rowThru; row++ ) { // Display a colored row background? if ( doRowBg && doThisRowBg ) { m_composer->fill( bgLeft, yPos, bgRight, textHt, rowBrush ); } doThisRowBg = ! doThisRowBg; // Left-most (row variable) column value. if ( rowVar->isDiscrete() ) { iid = (int) tableRow( row ); qStr = rowVar->m_itemList->itemName( iid ); } else if ( rowVar->isContinuous() ) { // CDB DECIMALS MOD if ( false ) { qStr.sprintf( "%1.*f", rowVar->m_displayDecimals, tableRow( row ) ); } else { qStr.sprintf( "%1.*f", m_rowDecimals, tableRow( row ) ); } } m_composer->font( textFont ); // use tableTextFont m_composer->pen( textPen ); // use tableTextFontColor m_composer->text( m_pageSize->m_marginLeft + s, yPos, rowWd, textHt, Qt::AlignVCenter|Qt::AlignLeft, qStr ); // Loop for each column value on this page. m_composer->font( valueFont ); // use tableValueFont m_composer->pen( valuePen ); // use tableValueFontColor out = vid + colFrom * tableVars() + row * tableCols() * tableVars(); for ( col = colFrom; col <= colThru; col++ ) { // Determine whether to hatch this cell cell = col + row * tableCols(); bool hatch = doRx && ! tableInRx( cell ); // Discrete variables use their item name. if ( outVar->isDiscrete() ) { iid = (int) tableVal( out ); qStr = outVar->m_itemList->itemName( iid ); } // Continuous variables use the current display units format. else if ( outVar->isContinuous() ) { qStr.sprintf( " %1.*f", outVar->m_displayDecimals, tableVal( out ) ); } // Display the output value. if ( hatch && doBlank ) { // draw nothing } else { m_composer->text( colXPos[col] + s, yPos, colWd, textHt, Qt::AlignVCenter|Qt::AlignRight, qStr ); } out += tableVars(); // RX hatching if ( hatch && ! doBlank && ! outVar->isDiagram() ) { x0 = colXPos[col] + s - m_padWd; x1 = colXPos[col] + s + m_padWd + colWd; m_composer->line( x0, yPos, x1, ( yPos + textHt ) ); m_composer->line( x0, ( yPos + textHt ), x1, yPos ); } } // Next table output variable. yPos += rowHt; } // Next table row. } // Next pageAcross. } // Next pageDown. // Be polite and stop the composer. m_composer->end(); // Clean up and return. delete[] colPage; delete[] colXPos; delete[] colText; delete[] shift; return; }
void BpDocument::composeTable1( void ) { // START THE STANDARD PREAMBLE USED BY ALL TABLE COMPOSITION FUNCTIONS. // WIN98 requires that we actually create a font here and use it for // font metrics rather than using the widget's font. QFont textFont( property()->string( "tableTextFontFamily" ), property()->integer( "tableTextFontSize" ) ); QPen textPen( property()->color( "tableTextFontColor" ) ); QFontMetrics textMetrics( textFont ); QFont titleFont( property()->string( "tableTitleFontFamily" ), property()->integer( "tableTitleFontSize" ) ); QPen titlePen( property()->color( "tableTitleFontColor" ) ); QFontMetrics titleMetrics( titleFont ); QFont valueFont( property()->string( "tableValueFontFamily" ), property()->integer( "tableValueFontSize" ) ); QPen valuePen( property()->color( "tableValueFontColor" ) ); QFontMetrics valueMetrics( valueFont ); // Store pixel resolution into local variables. double yppi = m_screenSize->m_yppi; double xppi = m_screenSize->m_xppi; double textHt, titleHt, valueHt; textHt = ( textMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; titleHt = ( titleMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; valueHt = ( valueMetrics.lineSpacing() + m_screenSize->m_padHt ) / yppi; // END THE STANDARD PREAMBLE USED BY ALL TABLE COMPOSITION FUNCTIONS QString results(""); translate( results, "BpDocument:Table:Results" ); // Determine variable label, value, and units minimum column widths. int nameWdPixels = 0; int resultWdPixels = 0; int unitsWdPixels = 0; int vid, len; QString qStr; EqVar *varPtr; // Loop for each output variable. for ( vid = 0; vid < tableVars(); vid++ ) { varPtr = tableVar(vid); // Label width. len = textMetrics.width( *(varPtr->m_label) ); if ( len > nameWdPixels ) { nameWdPixels = len; } // Units width. len = textMetrics.width( varPtr->m_displayUnits ); if ( len > unitsWdPixels ) { unitsWdPixels = len; } // Value width. if ( varPtr->isContinuous() ) { qStr.sprintf( "%1.*f", varPtr->m_displayDecimals, tableVal(vid) ); len = valueMetrics.width( qStr ); if ( len > resultWdPixels ) { resultWdPixels = len; } } else if ( varPtr->isDiscrete() ) { int iid = (int) tableVal(vid); qStr = varPtr->m_itemList->itemName(iid); len = valueMetrics.width( varPtr->m_itemList->itemName(iid) ); if ( len > resultWdPixels ) { resultWdPixels = len; } } } // Add padding for differences in screen and printer font sizes int wmPad = textMetrics.width( "WM" ); unitsWdPixels += wmPad; nameWdPixels += wmPad; resultWdPixels += valueMetrics.width( "WM" ); // If the name is too wide for the page, reduce the name field width. if ( ( nameWdPixels + unitsWdPixels + resultWdPixels + 2 * m_screenSize->m_padWd ) > m_screenSize->m_bodyWd ) { nameWdPixels = m_screenSize->m_bodyWd - resultWdPixels - unitsWdPixels - 2 * m_screenSize->m_padWd; } // Convert name and units widths from pixels to inches. double resultWd = (double) resultWdPixels / xppi; double nameWd = (double) nameWdPixels / xppi; double unitsWd = (double) unitsWdPixels / xppi; // Determine offset (inches) required to horizontally center the table. double offsetX = ( m_screenSize->m_bodyWd - nameWdPixels - resultWdPixels - ( unitsWdPixels - wmPad ) - 2 * m_screenSize->m_padWd ) / ( 2. * xppi ); // Determine column offsets. double nameColX = m_pageSize->m_marginLeft + offsetX; double resultColX = nameColX + nameWd + m_pageSize->m_padWd; double unitsColX = resultColX + resultWd + m_pageSize->m_padWd; // Open the composer and start with a new page. startNewPage( results, TocListOut ); double yPos = m_pageSize->m_marginTop + titleHt; // Print the table header. m_composer->font( titleFont ); // use tableTitleFont m_composer->pen( titlePen ); // use tableTitleFontColor qStr = m_eqTree->m_eqCalc->docDescriptionStore().stripWhiteSpace(); //if ( qStr.isNull() || qStr.isEmpty() ) //{ // translate( qStr, "BpDocument:NoRunDescription" ); //} m_composer->text( m_pageSize->m_marginLeft, yPos, // start at UL corner m_pageSize->m_bodyWd, titleHt, // width and height Qt::AlignVCenter|Qt::AlignCenter, // center alignment qStr ); // display description yPos += titleHt; // Draw each output variable on its own line. m_composer->font( textFont ); m_composer->pen( textPen ); for ( vid = 0; vid < tableVars(); vid++ ) { varPtr = tableVar(vid); if ( varPtr->isDiagram() ) { continue; } // Get the next y position. if ( ( yPos += textHt ) > m_pageSize->m_bodyEnd ) { startNewPage( results, TocBlank ); yPos = m_pageSize->m_marginTop; } // Write the variable name. m_composer->font( textFont ); // use tableTextFont m_composer->pen( textPen ); // use tableTextFontColor qStr = *(varPtr->m_label); // display label text m_composer->text( nameColX, yPos, // start at UL corner nameWd, textHt, // width and height Qt::AlignVCenter|Qt::AlignLeft, // left justified qStr ); // display label text // Continuous variable value and units. if ( varPtr->isContinuous() ) { qStr.sprintf( "%1.*f", varPtr->m_displayDecimals, tableVal(vid) ); m_composer->font( valueFont ); // use tableValueFont m_composer->pen( valuePen ); // use tableValueFontColor m_composer->text( resultColX, yPos, // start at UL corner resultWd, valueHt, // width and height Qt::AlignVCenter|Qt::AlignRight, // right justified qStr ); // display value text m_composer->font( textFont ); // use tableTextFont m_composer->pen( textPen ); // use tableTextFontColor m_composer->text( unitsColX, yPos, // start at UL corner unitsWd, textHt, // width and height Qt::AlignVCenter|Qt::AlignLeft, // left justified varPtr->displayUnits() ); // display units text } // Discrete variable value name else if ( varPtr->isDiscrete() ) { int id = (int) tableVal(vid); m_composer->font( valueFont ); // use tableValueFont m_composer->pen( valuePen ); // use tableValueFontColor m_composer->text( resultColX, yPos, // start at UL corner resultWd, valueHt, // width and height Qt::AlignVCenter|Qt::AlignRight, // right justify varPtr->m_itemList->itemName(id) ); // display item name } } // Write any prescription results if ( false && property()->boolean( "tableShading" ) ) { // Get the next y position. if ( ( yPos += textHt ) > m_pageSize->m_bodyEnd ) { startNewPage( results, TocBlank ); yPos = m_pageSize->m_marginTop; } // Write the prescription label m_composer->font( textFont ); // use tableTextFont m_composer->pen( textPen ); // use tableTextFontColor translate( qStr, "BpDocument:Results:RxVar:Label" ); m_composer->text( nameColX, yPos, // start at UL corner nameWd, textHt, // width and height Qt::AlignVCenter|Qt::AlignLeft, // left justified qStr ); // display label text // Write the result translate( qStr, tableInRx(0) ? "BpDocument:Results:RxVar:Yes" : "BpDocument:Results:RxVar:No" ); m_composer->font( valueFont ); // use tableValueFont m_composer->pen( valuePen ); // use tableValueFontColor m_composer->text( resultColX, yPos, // start at UL corner resultWd, valueHt, // width and height Qt::AlignVCenter|Qt::AlignRight, // right justify qStr ); // display item name } // Be polite and stop the composer. m_composer->end(); // Write the spreadsheet files composeTable1Spreadsheet(); composeTable1Html(); return; }
int AbstractMeter::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = WidgetWithBackground::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: valueChanged((*reinterpret_cast< double(*)>(_a[1]))); break; case 2: setValue((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: setValue((*reinterpret_cast< double(*)>(_a[1]))); break; default: ; } _id -= 4; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< double*>(_v) = minimum(); break; case 1: *reinterpret_cast< double*>(_v) = maximum(); break; case 2: *reinterpret_cast< double*>(_v) = value(); break; case 3: *reinterpret_cast< double*>(_v) = nominal(); break; case 4: *reinterpret_cast< double*>(_v) = critical(); break; case 5: *reinterpret_cast< QString*>(_v) = prefix(); break; case 6: *reinterpret_cast< QString*>(_v) = suffix(); break; case 7: *reinterpret_cast< QFont*>(_v) = valueFont(); break; case 8: *reinterpret_cast< double*>(_v) = valueOffset(); break; case 9: *reinterpret_cast< QFont*>(_v) = digitFont(); break; case 10: *reinterpret_cast< double*>(_v) = digitOffset(); break; } _id -= 11; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setMinimum(*reinterpret_cast< double*>(_v)); break; case 1: setMaximum(*reinterpret_cast< double*>(_v)); break; case 2: setValue(*reinterpret_cast< double*>(_v)); break; case 3: setNominal(*reinterpret_cast< double*>(_v)); break; case 4: setCritical(*reinterpret_cast< double*>(_v)); break; case 5: setPrefix(*reinterpret_cast< QString*>(_v)); break; case 6: setSuffix(*reinterpret_cast< QString*>(_v)); break; case 7: setValueFont(*reinterpret_cast< QFont*>(_v)); break; case 8: setValueOffset(*reinterpret_cast< double*>(_v)); break; case 9: setDigitFont(*reinterpret_cast< QFont*>(_v)); break; case 10: setDigitOffset(*reinterpret_cast< double*>(_v)); break; } _id -= 11; } else if (_c == QMetaObject::ResetProperty) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 11; } #endif // QT_NO_PROPERTIES return _id; }