Exemplo n.º 1
0
void PlotMarkerLegend::updateLegend(QwtLegend* legend) const
{
	if ( legend == NULL )
		return;

	if ( legend && testItemAttribute( QwtPlotItem::Legend ) && symbol() && symbol()->style() != QwtSymbol::NoSymbol )
	{
		QWidget *lgdItem = legend->find( this );
		if ( lgdItem == NULL )
		{
			lgdItem = legendItem();
			if ( lgdItem )
				legend->insert( this, lgdItem );
		}

		LegendItem *l = qobject_cast<LegendItem *>( lgdItem );
		if ( l )
			l->setIdentifierSize( symbol()->boundingSize() );
	}

	QWidget *lgdItem = legend->find( this );
	if ( testItemAttribute( QwtPlotItem::Legend ) )
	{
		LegendItem *label = qobject_cast<LegendItem *>( lgdItem );
		if ( label )
		{
			// paint the identifier
			const QSize sz = label->identifierSize();

			QPixmap identifier( sz.width(), sz.height() );
			identifier.fill( Qt::transparent );

			QPainter painter( &identifier );
			painter.setRenderHint( QPainter::Antialiasing, testRenderHint( QwtPlotItem::RenderAntialiased ) );
			drawLegendIdentifier( &painter, QRect( 0, 0, sz.width(), sz.height() ) );
			painter.end();

			const bool doUpdate = label->updatesEnabled();
			if ( doUpdate )
				label->setUpdatesEnabled( false );

			label->setText( title() );
			label->setIdentifier( identifier );
			label->setItemMode( legend->itemMode() );

			if ( doUpdate )
				label->setUpdatesEnabled( true );

			label->update();
		}
	}
	else
	{
		if ( lgdItem )
		{
			lgdItem->hide();
			lgdItem->deleteLater();
		}
	}
}
Exemplo n.º 2
0
bool plotsDialog::loadXml(bool init)
{
    tabs->clear();
    QFile file;
#ifdef Q_OS_WIN32
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName("plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy("plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName("plotTemp.xml");
    }
    else file.setFileName("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
    QDir dir = qApp->applicationDirPath();
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    /*dir.cdUp();*/
    QString bundleDir(dir.absolutePath());
    if(init)
    {
        QFile ofile(globalpara.caseName);
        file.setFileName(bundleDir+"/plotTemp.xml");
        if(file.exists())
            file.remove();
        if(!ofile.copy(bundleDir+"/plotTemp.xml"))
        {
            globalpara.reportError("Fail to generate temporary file for plots.",this);
            return false;
        }
        else file.setFileName(bundleDir+"/plotTemp.xml");
    }
    else file.setFileName(bundleDir+"/plotTemp.xml");
#endif
    QDomDocument doc;
    QDomElement plotData, currentPlot;
    int plotCount=0;
    Plot*newPlot;

    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        globalpara.reportError("Fail to open the xml file for plots!",this);
        return false;
    }
    else
    {
        if(!doc.setContent(&file))
        {
            globalpara.reportError("Fail to set DomDoc to file content when loading xml file for plots!",this);
            file.close();
            return false;
        }
        else
        {
            if(doc.elementsByTagName("plotData").count()==0)
            {
                globalpara.reportError("Error! There is no <plotData> branch in the case xml file!",this);
                file.close();
                return false;
            }
            else
                plotData = doc.elementsByTagName("plotData").at(0).toElement();

            plotCount = plotData.childNodes().count();
            for(int i = 0; i < plotCount; i++)
            {
                currentPlot = plotData.childNodes().at(i).toElement();
                if(currentPlot.attribute("plotType")=="parametric")
                {
                    QDomElement currentRun,runInput,runOutput;
                    double currentInput;
                    int axis_info[8];
                    QStringList currentOutput, xValues, axis_name, info;
                    QMultiMap<double,double> allData;
                    axis_name.append(currentPlot.attribute("xAxisName"));
                    axis_name= axis_name + currentPlot.attribute("yAxisName").split(",");
                    info = currentPlot.attribute("scaleInfo").split(",");
                    for(int j = 0; j < 8; j++)
                        axis_info[j] = info.at(j).toInt();
                    int nRuns = currentPlot.elementsByTagName("Run").count(), nOutputs = currentPlot.attribute("outputs").toInt();
                    for(int j = 0; j < nRuns; j++)
                    {
                        currentOutput.clear();
                        currentRun = currentPlot.elementsByTagName("Run").at(j).toElement();
                        runInput = currentRun.elementsByTagName("Input").at(0).toElement();
                        currentInput = runInput.elementsByTagName("value").at(0).toElement().text().toDouble();
                        xValues.append(QString::number(currentInput));
                        for(int p = 0; p < nOutputs; p++)
                        {
                            runOutput = currentRun.elementsByTagName("Output").at(p).toElement();
                            currentOutput.append(runOutput.elementsByTagName("value").at(0).toElement().text());
                            allData.insert(currentInput,currentOutput.at(p).toDouble());
                        }
                    }


                    newPlot = new Plot(allData,xValues,nOutputs,axis_info,axis_name);


                }
                else if(currentPlot.attribute("plotType")=="property")
                {
                    QString fluid = currentPlot.attribute("fluid"),
                            subType = currentPlot.attribute("subType"),
                            unit = currentPlot.attribute("unitSystem");

                    newPlot = new Plot(fluid,subType,unit);
                    QDomElement currentCurve, currentPoint;

                    newPlot->curvePoints.clear();
                    for(int i = 0; i < currentPlot.childNodes().count(); i++)
                    {
                        if(currentPlot.childNodes().at(i).toElement().attribute("type")=="custom")
                        {
                            addvalue*value;
                            newPlot->addvaluelist.clear();
                            currentCurve = currentPlot.childNodes().at(i).toElement();
                            QString title = currentCurve.tagName();
                            for(int j = 0; j < currentCurve.childNodes().count(); j++)
                            {
                                if(currentCurve.childNodes().at(j).toElement().attribute("order")==QString::number(j))
                                {
                                    value = new addvalue;
                                    currentPoint = currentCurve.childNodes().at(j).toElement();
                                    value->index = currentPoint.attribute("index").toInt();
                                    value->add_temperature = currentPoint.attribute("t").toDouble();
                                    value->add_pressure = currentPoint.attribute("p").toDouble();
                                    value->add_concentration = currentPoint.attribute("c").toDouble();
                                    value->add_enthalpy = currentPoint.attribute("h").toDouble();
//                                    qDebug()<<"adding a new point"<<currentPoint.attribute("index")<<"t"<<currentPoint.attribute("t")<<"p"<<currentPoint.attribute("p")<<"c"<<currentPoint.attribute("c");
                                    newPlot->addvaluelist<<value;
                                }
                            }

                            if(subType == "Duhring")
                                newPlot->setupNewPropertyCurve(title,true);
                            else if(subType == "Clapeyron")
                                newPlot->setupNewPropertyCurve(title,false);
                        }
                    }


                }
                newPlot->setTitle(currentPlot.tagName());

                //load the plot settings
                QDomElement general, legend, grid, curve;

                //general
                if(currentPlot.elementsByTagName("general").count()>0)
                {
                    general = currentPlot.elementsByTagName("general").at(0).toElement();
                    QString bgColor, lMargin, rMargin, tMargin, bMargin, plotTitle, xTitle, yTitle;
                    bgColor = general.attribute("bgColor");
                    newPlot->setCanvasBackground(QColor(bgColor));
                    lMargin = general.attribute("lMargin");
                    rMargin = general.attribute("rMargin");
                    tMargin = general.attribute("tMargin");
                    bMargin = general.attribute("bMargin");
                    newPlot->setContentsMargins(lMargin.toInt(),tMargin.toInt(),rMargin.toInt(),bMargin.toInt());
                    plotTitle = general.attribute("plotTitle");
                    newPlot->setTitle(plotTitle);
                    xTitle = general.attribute("xTitle");
                    yTitle = general.attribute("yTitle");
                    newPlot->setAxisTitle(QwtPlot::xBottom,xTitle);
                    newPlot->setAxisTitle(QwtPlot::yLeft,yTitle);

                }

                //legend
                if(currentPlot.elementsByTagName("legend").count()>0)
                {
                    legend = currentPlot.elementsByTagName("legend").at(0).toElement();
                    QString plotLegend, extInt, extPos, nCol, legendSize;
                    plotLegend = legend.attribute("plotLegend");
                    if(plotLegend == "on")
                    {
                        QwtLegend* externalLegend=NULL;
                        LegendItem* internalLegend = new LegendItem();
                        newPlot->externalLegend = externalLegend;
                        newPlot->internalLegend = internalLegend;
                        internalLegend->attach(newPlot);
                        internalLegend->setBorderRadius( 4 );
                        internalLegend->setMargin( 0 );
                        internalLegend->setSpacing( 4 );
                        internalLegend->setItemMargin( 2 );
                        internalLegend->setMaxColumns(4);
                        internalLegend->setAlignment(Qt::AlignBottom|Qt::AlignRight);
                        extInt = legend.attribute("extInt");
                        if(extInt == "ext")
                        {
                            internalLegend->setVisible(false);
                            externalLegend = new QwtLegend();
                            extPos = legend.attribute("extPos");//0=L, 1=R, 2=B, 3=T
                            newPlot->insertLegend(externalLegend,QwtPlot::LegendPosition(extPos.toInt()));
                        }
                        else if(extInt == "int")
                        {
                            internalLegend->setVisible(true);
                            nCol = legend.attribute("nCol");
                            legendSize = legend.attribute("legendSize");

                            // other setting
                            newPlot->internalLegend->setMaxColumns(nCol.toInt());
                            QFont font = newPlot->internalLegend->font();
                            font.setPointSize( legendSize.toInt());
                            newPlot->internalLegend->setFont( font );
                        }
                    }
                }

                //grid
                if(currentPlot.elementsByTagName("grid").count()>0)
                {
                    grid = currentPlot.elementsByTagName("grid").at(0).toElement();
                    QString xMaj, yMaj, xMin, yMin, majColor, minColor, majSize, minSize, majStyle, minStyle;
                    xMaj = grid.attribute("xMaj");
                    yMaj = grid.attribute("yMaj");
                    xMin = grid.attribute("xMin");
                    yMin = grid.attribute("yMin");
                    majColor = grid.attribute("majColor");
                    minColor = grid.attribute("minColor");
                    majSize = grid.attribute("majSize");
                    minSize = grid.attribute("minSize");
                    majStyle = grid.attribute("majStyle");
                    minStyle = grid.attribute("minStyle");
                    newPlot->grid->enableX(xMaj=="on");
                    newPlot->grid->enableY(yMaj == "on");
                    newPlot->grid->enableXMin(xMin=="on");
                    newPlot->grid->enableYMin(yMin=="on");
                    if(newPlot->grid->xEnabled()||newPlot->grid->yEnabled())
                        newPlot->grid->setMajorPen(QColor(majColor),majSize.toInt(),Qt::PenStyle(majStyle.toInt()));
                    if(newPlot->grid->xMinEnabled()||newPlot->grid->yMinEnabled())
                        newPlot->grid->setMinorPen(QColor(minColor),minSize.toInt(),Qt::PenStyle(minStyle.toInt()));
                }

                //curve
                if(currentPlot.elementsByTagName("curve").count()>0)
                {
                    curve = currentPlot.elementsByTagName("curve").at(0).toElement();
                    if(curve.childNodes().count()==newPlot->curvelist.count())
                    {
                        QDomElement currentCurve;
                        QwtPlotCurve *thisCurve;
                        QString lineColor, lineSize, lineType, isVisible;
                        for(int i = 0; i < newPlot->curvelist.count(); i++)
                        {
                            currentCurve = curve.elementsByTagName(newPlot->curvelist[i]->title().text().replace(" ","")).at(0).toElement();
                            thisCurve = newPlot->curvelist[i];
                            lineColor = currentCurve.attribute("lineColor");
                            lineSize = currentCurve.attribute("lineSize");
                            lineType = currentCurve.attribute("lineType");
                            isVisible = currentCurve.attribute("isVisible");
                            thisCurve->setPen(QColor(lineColor),lineSize.toInt(),Qt::PenStyle(lineType.toInt()));
                            if(isVisible=="true")
                                thisCurve->setVisible(true);
                            else if(isVisible=="false")
                                thisCurve->setVisible(false);
                        }
                    }
                }


                tabs->insertTab(-1,newPlot,currentPlot.tagName());
                newPlot->replot();
            }
            file.close();
            return true;
        }
    }
}
Exemplo n.º 3
0
 void fill(Plot* plot)
 {
     LegendItem* legend = plot->getLegend();
     LegendItem* donorLegend = donor->getLegend();
     legend->setVisible(donorLegend->isVisible());
     legend->setFont(donorLegend->font());
     legend->setMaxColumns(donorLegend->maxColumns());
     legend->setBackgroundOpacity(donorLegend->backgroundBrush().color().alpha());
     legend->setAlignment(donorLegend->alignment());
     plot->replot();
 }