本文整理汇总了C++中QwtPlotCurve::pen方法的典型用法代码示例。如果您正苦于以下问题:C++ QwtPlotCurve::pen方法的具体用法?C++ QwtPlotCurve::pen怎么用?C++ QwtPlotCurve::pen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QwtPlotCurve
的用法示例。
在下文中一共展示了QwtPlotCurve::pen方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onLegendChecked
void QcepPlot::onLegendChecked(const QVariant &itemInfo, bool on, int index)
{
// if (g_Application) {
// g_Application->printMessage(tr("QxrdPlot::onLegendChecked(%1,%2,%3)").arg(itemInfo.toString()).arg(on).arg(index));
// }
QwtPlotItem *item = infoToItem(itemInfo);
if (item) {
QwtPlotCurve *pc = dynamic_cast<QwtPlotCurve*>(item);
if (pc) {
QPen pen = pc->pen();
const QwtSymbol *oldsym = pc->symbol();
QwtSymbol *sym = NULL;
if (oldsym) {
sym = new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
}
if (on) {
pen.setWidth(3);
if (sym) {
sym->setSize(9,9);
}
} else {
pen.setWidth(1);
if (sym) {
sym->setSize(5,5);
}
}
pc->setPen(pen);
if (sym) {
pc->setSymbol(sym);
}
}
replot();
}
}
示例2: enableLegend
/*!
\brief Enable or disable the legend
\param tf \c TRUE (enabled) or \c FALSE (disabled)
\param curveKey Key of a existing curve.
If curveKey < 0 the legends for all
curves will be updated.
\sa QwtPlot::setAutoLegend()
\sa QwtPlot::setLegendPos()
*/
void QwtPlot::enableLegend(
#ifndef QWT_NO_LEGEND
bool enable, long curveKey
#else
bool, long
#endif
)
{
#ifndef QWT_NO_LEGEND
QwtPlotCurve *curCurve;
bool isUpdateEnabled = d_legend->isUpdatesEnabled();
d_legend->setUpdatesEnabled(FALSE);
if ( curveKey < 0 ) // legends for all curves
{
if ( enable )
{
if ( d_legend->itemCnt() < d_curves->count() )
{
// not all curves have a legend
d_legend->clear();
QIntDictIterator<QwtPlotCurve> itc(*d_curves);
itc.toFirst();
while ((curCurve = itc.current()))
{
d_legend->appendItem(curCurve->title(),
curCurve->symbol(), curCurve->pen(), itc.currentKey());
++itc;
}
}
}
else
{
if ( d_legend->itemCnt() > 0 )
d_legend->clear();
}
}
else
{
uint index = d_legend->findFirstKey(curveKey);
if ( enable )
{
curCurve = d_curves->find(curveKey);
if ( curCurve && ( index >= d_legend->itemCnt() ) )
{
// curve exists and has no legend
d_legend->appendItem(curCurve->title(),
curCurve->symbol(), curCurve->pen(), curveKey);
}
}
else
{
if ( index < d_legend->itemCnt() )
d_legend->removeItem(index);
}
}
d_legend->setUpdatesEnabled(isUpdateEnabled);
updateLayout();
#endif
}
示例3: savePlotSettings
void plotsDialog::savePlotSettings()
{
#ifdef Q_OS_WIN32
QFile file("plotTemp.xml");
#endif
#ifdef Q_OS_MAC
QDir dir = qApp->applicationDirPath();
/*dir.cdUp();*/
/*dir.cdUp();*/
/*dir.cdUp();*/
QString bundleDir(dir.absolutePath());
QFile ofile(globalpara.caseName),file(bundleDir+"/plotTemp.xml");
#endif
QTextStream stream;
stream.setDevice(&file);
QDomDocument doc;
QDomElement plotData, currentPlot, general, legend, grid, curve;
if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
{
globalpara.reportError("Failed to open and load case file for plot data.",this);
return;
}
else
{
if(!doc.setContent(&file))
{
globalpara.reportError("Failed to set document for the xml file for plot data.",this);
file.close();
return;
}
else
{
plotData = doc.elementsByTagName("plotData").at(0).toElement();
for(int i = 0; i < tabs->count(); i++)
{
Plot* set_plot = dynamic_cast<Plot*>(tabs->widget(i));
currentPlot = plotData.elementsByTagName(tabs->tabText(i)).at(0).toElement();
//general
if(currentPlot.elementsByTagName("general").count()==0)
{
general = doc.createElement("general");
currentPlot.appendChild(general);
}
else general = currentPlot.elementsByTagName("general").at(0).toElement();
general.setAttribute("bgColor",set_plot->canvasBackground().color().name());
general.setAttribute("lMargin",set_plot->contentsMargins().left());
general.setAttribute("rMargin",set_plot->contentsMargins().right());
general.setAttribute("tMargin",set_plot->contentsMargins().top());
general.setAttribute("bMargin",set_plot->contentsMargins().bottom());
general.setAttribute("plotTitle",set_plot->title().text());
general.setAttribute("xTitle",set_plot->axisTitle(QwtPlot::xBottom).text());
general.setAttribute("yTitle",set_plot->axisTitle(QwtPlot::yLeft).text());
//legend
if(currentPlot.elementsByTagName("legend").count()==0)
{
legend = doc.createElement("legend");
currentPlot.appendChild(legend);
}
else legend = currentPlot.elementsByTagName("legend").at(0).toElement();
if(set_plot->externalLegend!=NULL||set_plot->internalLegend->isVisible())
{
legend.setAttribute("plotLegend","on");
if(set_plot->internalLegend->isVisible())
{
legend.setAttribute("extInt","int");
legend.setAttribute("nCol",set_plot->internalLegend->maxColumns());
legend.setAttribute("legendSize",set_plot->internalLegend->font().pointSize());
}
else if(set_plot->externalLegend!=NULL)
{
legend.setAttribute("extInt","ext");
legend.setAttribute("extPos",0);
}
}
else legend.setAttribute("plotLegend","off");
//grid
if(currentPlot.elementsByTagName("grid").count()==0)
{
grid = doc.createElement("grid");
currentPlot.appendChild(grid);
}
else grid = currentPlot.elementsByTagName("grid").at(0).toElement();
if(set_plot->grid->xEnabled()||set_plot->grid->yEnabled())
{
if(set_plot->grid->xEnabled())
grid.setAttribute("xMaj","on");
else grid.setAttribute("xMaj","off");
if(set_plot->grid->yEnabled())
grid.setAttribute("yMaj","on");
else grid.setAttribute("yMaj","off");
grid.setAttribute("majColor",set_plot->grid->majorPen().color().name());
grid.setAttribute("majSize",set_plot->grid->majorPen().width());
int styleCode;
if(set_plot->grid->majorPen().style()==Qt::NoPen)
//.........这里部分代码省略.........
示例4: reset
/*!
Reset color and fonts of a plot
\sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::reset(QwtPlot *plot) const
{
if ( d_cache == 0 )
return;
QFont *font;
QColor *color;
if ( plot->d_lblTitle )
{
QPalette palette = plot->d_lblTitle->palette();
palette.setColor(
QPalette::Active, QColorGroup::Foreground, d_cache->titleColor);
plot->d_lblTitle->setPalette(palette);
plot->d_lblTitle->setFont(d_cache->titleFont);
}
if ( plot->d_legend )
{
QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
{
const int key = it.currentKey();
font = d_cache->legendFonts.find(key);
if ( font )
w->setFont(*font);
if ( w->inherits("QwtLegendButton") )
{
QwtLegendButton *btn = (QwtLegendButton *)w;
QwtSymbol symbol = btn->symbol();
color = d_cache->curveSymbolPenColors.find(key);
if ( color )
{
QPen pen = symbol.pen();
pen.setColor(*color);
symbol.setPen(pen);
}
color = d_cache->curveSymbolBrushColors.find(key);
if ( color )
{
QBrush brush = symbol.brush();
brush.setColor(*color);
symbol.setBrush(brush);
}
btn->setSymbol(symbol);
color = d_cache->curveColors.find(key);
if ( color )
{
QPen pen = btn->curvePen();
pen.setColor(*color);
btn->setCurvePen(pen);
}
}
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
QwtScale *scale = plot->d_scale[axis];
if ( scale )
{
QPalette palette = scale->palette();
palette.setColor(QPalette::Active, QColorGroup::Foreground,
d_cache->scaleColor[axis]);
scale->setPalette(palette);
scale->setFont(d_cache->scaleFont[axis]);
scale->setTitleColor(d_cache->scaleTitleColor[axis]);
scale->setTitleFont(d_cache->scaleTitleFont[axis]);
int startDist, endDist;
scale->minBorderDist(startDist, endDist);
scale->setBorderDist(startDist, endDist);
}
}
plot->setBackgroundColor(d_cache->widgetBackground);
plot->setCanvasBackground(d_cache->canvasBackground);
QPen pen = plot->d_grid->majPen();
pen.setColor(d_cache->gridColors[0]);
plot->d_grid->setMajPen(pen);
pen = plot->d_grid->minPen();
pen.setColor(d_cache->gridColors[1]);
plot->d_grid->setMinPen(pen);
QIntDictIterator<QwtPlotCurve> itc(*plot->d_curves);
for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
{
const int key = itc.currentKey();
//.........这里部分代码省略.........
示例5: apply
/*!
Change color and fonts of a plot
\sa QwtPlotPrintFilter::apply
*/
void QwtPlotPrintFilter::apply(QwtPlot *plot) const
{
QwtPlotPrintFilter *that = (QwtPlotPrintFilter *)this;
delete that->d_cache;
that->d_cache = new QwtPlotPrintFilterCache;
QwtPlotPrintFilterCache &cache = *that->d_cache;
if ( plot->d_lblTitle )
{
QPalette palette = plot->d_lblTitle->palette();
cache.titleColor = palette.color(
QPalette::Active, QColorGroup::Foreground);
palette.setColor(QPalette::Active, QColorGroup::Foreground,
color(cache.titleColor, Title));
plot->d_lblTitle->setPalette(palette);
cache.titleFont = plot->d_lblTitle->font();
plot->d_lblTitle->setFont(font(cache.titleFont, Title));
}
if ( plot->d_legend )
{
QIntDictIterator<QWidget> it = plot->d_legend->itemIterator();
for ( QWidget *w = it.toFirst(); w != 0; w = ++it)
{
const int key = it.currentKey();
cache.legendFonts.insert(it.currentKey(), new QFont(w->font()));
w->setFont(font(w->font(), Legend, key));
if ( w->inherits("QwtLegendButton") )
{
QwtLegendButton *btn = (QwtLegendButton *)w;
QwtSymbol symbol = btn->symbol();
QPen pen = symbol.pen();
QBrush brush = symbol.brush();
pen.setColor(color(pen.color(), CurveSymbol, key));
brush.setColor(color(brush.color(), CurveSymbol, key));
symbol.setPen(pen);
symbol.setBrush(brush);
btn->setSymbol(symbol);
pen = btn->curvePen();
pen.setColor(color(pen.color(), Curve, key));
btn->setCurvePen(pen);
}
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
QwtScale *scale = plot->d_scale[axis];
if ( scale )
{
cache.scaleColor[axis] = scale->palette().color(
QPalette::Active, QColorGroup::Foreground);
QPalette palette = scale->palette();
palette.setColor(QPalette::Active, QColorGroup::Foreground,
color(cache.scaleColor[axis], AxisScale, axis));
scale->setPalette(palette);
cache.scaleFont[axis] = scale->font();
scale->setFont(font(cache.scaleFont[axis], AxisScale, axis));
cache.scaleTitleColor[axis] = scale->titleColor();
scale->setTitleColor(
color(cache.scaleTitleColor[axis], AxisTitle, axis));
cache.scaleTitleFont[axis] = scale->titleFont();
scale->setTitleFont(
font(cache.scaleTitleFont[axis], AxisTitle, axis));
int startDist, endDist;
scale->minBorderDist(startDist, endDist);
scale->setBorderDist(startDist, endDist);
}
}
cache.widgetBackground = plot->backgroundColor();
plot->setBackgroundColor(color(cache.widgetBackground, WidgetBackground));
cache.canvasBackground = plot->canvasBackground();
plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));
QPen pen = plot->d_grid->majPen();
cache.gridColors[0] = pen.color();
pen.setColor(color(pen.color(), MajorGrid));
plot->d_grid->setMajPen(pen);
pen = plot->d_grid->minPen();
cache.gridColors[1] = pen.color();
pen.setColor(color(pen.color(), MinorGrid));
plot->d_grid->setMinPen(pen);
//.........这里部分代码省略.........
示例6: reset
void QwtPlotPrintFilter::reset(QwtPlotItem *item) const
{
if ( d_data->cache == 0 )
return;
const PrivateData::Cache &cache = *d_data->cache;
switch(item->rtti())
{
case QwtPlotItem::Rtti_PlotGrid:
{
QwtPlotGrid *grid = (QwtPlotGrid *)item;
QPen pen = grid->majPen();
pen.setColor(cache.gridColors[0]);
grid->setMajPen(pen);
pen = grid->minPen();
pen.setColor(cache.gridColors[1]);
grid->setMinPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotCurve:
{
QwtPlotCurve *c = (QwtPlotCurve *)item;
QwtSymbol symbol = c->symbol();
if ( cache.curveSymbolPenColors.contains(c) )
{
symbol.setPen(cache.curveSymbolPenColors[c]);
}
if ( cache.curveSymbolBrushColors.contains(c) )
{
QBrush brush = symbol.brush();
brush.setColor(cache.curveSymbolBrushColors[c]);
symbol.setBrush(brush);
}
c->setSymbol(symbol);
if ( cache.curveColors.contains(c) )
{
QPen pen = c->pen();
pen.setColor(cache.curveColors[c]);
c->setPen(pen);
}
break;
}
case QwtPlotItem::Rtti_PlotMarker:
{
QwtPlotMarker *m = (QwtPlotMarker *)item;
if ( cache.markerFonts.contains(m) )
{
QwtText label = m->label();
label.setFont(cache.markerFonts[m]);
m->setLabel(label);
}
if ( cache.markerLabelColors.contains(m) )
{
QwtText label = m->label();
label.setColor(cache.markerLabelColors[m]);
m->setLabel(label);
}
if ( cache.markerLineColors.contains(m) )
{
QPen pen = m->linePen();
pen.setColor(cache.markerLineColors[m]);
m->setLinePen(pen);
}
QwtSymbol symbol = m->symbol();
if ( cache.markerSymbolPenColors.contains(m) )
{
QPen pen = symbol.pen();
pen.setColor(cache.markerSymbolPenColors[m]);
symbol.setPen(pen);
}
if ( cache.markerSymbolBrushColors.contains(m) )
{
QBrush brush = symbol.brush();
brush.setColor(cache.markerSymbolBrushColors[m]);
symbol.setBrush(brush);
}
m->setSymbol(symbol);
break;
}
default:
break;
}
}
示例7: apply
void QwtPlotPrintFilter::apply(QwtPlotItem *item) const
{
PrivateData::Cache &cache = *d_data->cache;
switch(item->rtti())
{
case QwtPlotItem::Rtti_PlotGrid:
{
QwtPlotGrid *grid = (QwtPlotGrid *)item;
QPen pen = grid->majPen();
cache.gridColors[0] = pen.color();
pen.setColor(color(pen.color(), MajorGrid));
grid->setMajPen(pen);
pen = grid->minPen();
cache.gridColors[1] = pen.color();
pen.setColor(color(pen.color(), MinorGrid));
grid->setMinPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotCurve:
{
QwtPlotCurve *c = (QwtPlotCurve *)item;
QwtSymbol symbol = c->symbol();
QPen pen = symbol.pen();
cache.curveSymbolPenColors.insert(c, pen.color());
pen.setColor(color(pen.color(), CurveSymbol));
symbol.setPen(pen);
QBrush brush = symbol.brush();
cache.curveSymbolBrushColors.insert(c, brush.color());
brush.setColor(color(brush.color(), CurveSymbol));
symbol.setBrush(brush);
c->setSymbol(symbol);
pen = c->pen();
cache.curveColors.insert(c, pen.color());
pen.setColor(color(pen.color(), Curve));
c->setPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotMarker:
{
QwtPlotMarker *m = (QwtPlotMarker *)item;
QwtText label = m->label();
cache.markerFonts.insert(m, label.font());
label.setFont(font(label.font(), Marker));
cache.markerLabelColors.insert(m, label.color());
label.setColor(color(label.color(), Marker));
m->setLabel(label);
QPen pen = m->linePen();
cache.markerLineColors.insert(m, pen.color());
pen.setColor(color(pen.color(), Marker));
m->setLinePen(pen);
QwtSymbol symbol = m->symbol();
pen = symbol.pen();
cache.markerSymbolPenColors.insert(m, pen.color());
pen.setColor(color(pen.color(), MarkerSymbol));
symbol.setPen(pen);
QBrush brush = symbol.brush();
cache.markerSymbolBrushColors.insert(m, brush.color());
brush.setColor(color(brush.color(), MarkerSymbol));
symbol.setBrush(brush);
m->setSymbol(symbol);
break;
}
default:
break;
}
}
示例8: onPropertyValueChanged
void QwtPlotPropertySetDialog::onPropertyValueChanged(QtProperty * property, const QVariant & value)
{
if(!m_enableSet)
return;
int id = m_property_id.getPropertyID(property);
if (id < ID_CurveIDBase)
{
switch(id)
{
case ID_PlotTitle:
m_plot->setTitle(value.toString());
return;
case ID_PlotFooter:
m_plot->setFooter(value.toString());
return;
case ID_PlotCanvasBackground:
m_plot->setCanvasBackground(QBrush(value.value<QColor>()));
return;
case ID_PlotEnableZoomerScroll:
m_plot->enableZoomerScroll(value.toBool());
return;
case ID_PlotAxisSet:
setAxisEnable(value.toInt());
return;
case ID_XBottomScale:
setAxisScaleDrawStyle(QwtPlot::xBottom,value);
return;
case ID_XTopScale:
setAxisScaleDrawStyle(QwtPlot::xTop,value);
return;
case ID_YLeftScale:
setAxisScaleDrawStyle(QwtPlot::yLeft,value);
return;
case ID_YRightScale:
setAxisScaleDrawStyle(QwtPlot::yRight,value);
return;
case ID_XBottomDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::xBottom,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_XTopDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::xTop,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_YLeftDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::yLeft,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_YRightDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::yRight,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_XBottomInterval:
case ID_XTopInterval:
case ID_YLeftInterval:
case ID_YRightInterval:
setAxisScale(id,value.toPointF());
return;
case ID_XBottomTitle:
case ID_XTopTitle:
case ID_YLeftTitle:
case ID_YRightTitle:
setAxisTitle(id,value.toString());
return;
case ID_XBottomLabelRotation:
case ID_XTopLabelRotation:
case ID_YLeftLabelRotation:
case ID_YRightLabelRotation:
setAxislabelRotation(id,value.toDouble());
return;
}
}
else
{
QwtPlotCurve* cur = getCurvePtr(id);
if(!cur)
return;
const int propertyID = getCurvePropertyID(id);
if (ID_CurveTitle == propertyID)
{
cur->setTitle(value.toString());
return;
}
QPen newPen(cur->pen());
switch (propertyID) {
case ID_CurveColore:
newPen.setColor(value.value<QColor>());
break;
case ID_CurveWidth:
newPen.setWidth(value.toInt());
break;
case ID_CurvePenStyle:
newPen.setStyle(order2penStyle(value.toInt()));
break;
}
cur->setPen(newPen);
}
}
示例9: data
QVariant CurvesModel::data(const QModelIndex& index, int role) const
{
SolvWidget* solv = solvers->at(index.row());
QwtPlotCurve * curve = solv->curve;
QColor col = curve->pen().color();
int bright = col.red() + 2*col.green() + col.blue();
QwtSymbol::Style symSty;
switch(index.column()) {
case 0:// title
switch(role) {
case Qt::DisplayRole :
case Qt::EditRole:
return solv->getTitle();
}
break;
case 1:// line color
switch(role) {
case Qt::BackgroundRole:
return QBrush(col);
case Qt::ForegroundRole:
if(bright > 600 ) return QBrush(Qt::darkGray);
return QBrush(Qt::white);
case Qt::DisplayRole:
return QVariant(colorName(col));
case Qt::EditRole:
case Qt::UserRole:
return QVariant(col);
}
break;
case 2:// line style
switch(role) {
case Qt::DecorationRole:
return penIcon(solv->curve->pen());
case Qt::DisplayRole :
return penStyles[solv->curve->pen().style()];
case Qt::EditRole :
return solv->curve->pen().style();
}
break;
case 3:// line width
switch(role) {
case Qt::DecorationRole:
return penIcon(solv->curve->pen());
case Qt::DisplayRole :
return QString("%1").arg(solv->curve->pen().widthF(),4,'f',2);
case Qt::EditRole :
return solv->curve->pen().widthF();
}
break;
case 4:// symbol style
if(curve->symbol() == NULL) {
symSty = QwtSymbol::NoSymbol;
} else {
symSty = curve->symbol()->style();
}
switch(role) {
case Qt::EditRole :
return QVariant(symSty);
case Qt::DisplayRole :
return SymbolStyleDelegate::symName(symSty);
}
break;
case 5:// symbol color
if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol) {
col= curve->symbol()->pen().color();
} // default to curve pen color
switch(role) {
case Qt::BackgroundRole:
return QBrush(col);
case Qt::ForegroundRole:
if(bright > 600 ) return QBrush(Qt::darkGray);
return QBrush(Qt::white);
case Qt::DisplayRole :
if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol) {
return ("No Symbol");
}
return QVariant(colorName(col)) ;
case Qt::EditRole:
case Qt::UserRole:
return QVariant(col);
}
break;
case 6: // symbol size
switch(role) {
//case Qt::DecorationRole:
//return penIcon(solv->curve->pen());
case Qt::DisplayRole :
if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol ) {
return QString("%1").arg(curve->symbol()->size().width());
}
break;
case Qt::EditRole :
case Qt::UserRole:
if(curve->symbol() != NULL && curve->symbol()->style() != QwtSymbol::NoSymbol ) {
return curve->symbol()->size().width();
}
return 7;
}
}
return QVariant();
//.........这里部分代码省略.........
示例10: setData
bool CurvesModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
SolvWidget* solv = solvers->at(index.row());
QwtPlotCurve* curve = solv->curve;
QPen pen = curve->pen(); /// This makes a copy of Pen
QColor col;
Qt::PenStyle ps;
QwtSymbol *symbol;
QwtSymbol::Style symbolStyle;
QBrush brush;
QSize symSize;
bool ok;
double lw;
int ss;
if( role != Qt::EditRole ) return false;
switch(index.column()) {
case 0:// title
if(value.toString().size() > 1) {
QString newTitle = value.toString();
if( newTitle != solv->getTitle() ) {
solv->setTitle(value.toString());
emit newdata();
return true;
}
}
return false;
case 1:// line color
col = value.value<QColor>();
if(pen.color() != col ) {
pen.setColor(col);
curve->setPen(pen);
solv->setColor(col);
emit newdata();
return true;
}
return false;
case 2:// line style
ps = Qt::PenStyle(value.toInt());
if( ps != pen.style()) {
pen.setStyle(ps);
curve->setPen(pen);
emit newdata();
return true;
}
return false;
case 3:// line width
lw = value.toDouble(&ok);
if(ok && (lw != curve->pen().widthF())) {
pen.setWidthF(lw);
curve->setPen(pen);
emit newdata();
return true;
}
return false;
case 4:// symbol style
symbolStyle = QwtSymbol::Style(value.toInt());
if(curve->symbol() == NULL) {
if(symbolStyle == QwtSymbol::NoSymbol ) return false;
pen.setStyle(Qt::SolidLine);
symbol = new QwtSymbol(symbolStyle,QBrush(),pen,QSize(7,7));//Qt::transparent
} else {
if(curve->symbol()->style() == symbolStyle) return false;
if(symbolStyle == QwtSymbol::NoSymbol) {
symbol = NULL;
} else {
symbol = new QwtSymbol(symbolStyle,curve->symbol()->brush(),curve->symbol()->pen(),curve->symbol()->size());
}
}
curve->setSymbol(symbol);
emit newdata();
return true;
case 5:// symbol color
col = value.value<QColor>();
if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol ) return false;
if(curve->symbol()->pen().color() == col ) return false;
pen = curve->symbol()->pen();
pen.setColor(col);
symbol = new QwtSymbol(curve->symbol()->style(),curve->symbol()->brush(),pen,curve->symbol()->size());
curve->setSymbol(symbol);
emit newdata();
return true;
case 6: // symbol size
ss = value.toInt();
if(ss < 1) return false;
if(curve->symbol() == NULL || curve->symbol()->style() == QwtSymbol::NoSymbol ) return false;
if(curve->symbol()->size().width() == ss ) return false;
symbol = new QwtSymbol(curve->symbol()->style(),curve->symbol()->brush(),curve->symbol()->pen(),QSize(ss,ss));
curve->setSymbol(symbol);
emit newdata();
return false;
}
return QAbstractItemModel::setData(index, value, role);
}
示例11: exportPlot
void PlotExporter::exportPlot(QwtPlot *plot, const QRectF &zoom)
{
QSizeF guessedDimensions;
ExportPlotToImageDialog::Parameters p = m_exportDlg->parameters();
m_exportDlg->setAspectRatio(plot->size().width() / plot->size().height());
while (m_exportDlg->exec() == QDialog::Accepted) {
p = m_exportDlg->parameters();
QString path;
if (p.path.length() < 0) {
QMessageBox::warning(nullptr, QObject::tr("Invalid input"), QObject::tr("Invalid path"));
continue;
}
if (!m_supportedFormats.contains(p.format)) {
QMessageBox::warning(nullptr, QObject::tr("Invalid input"), QObject::tr("Invalid output format"));
continue;
}
if (p.path.endsWith("." + p.format))
path = p.path;
else
path = p.path + "." + p.format;
/* Create a temporary QwtPlot to use to write the chart to file */
QwtPlot exPlot;
QwtPlotZoomer exPlorZoomer(exPlot.canvas());
exPlorZoomer.zoom(zoom);
exPlot.setCanvasBackground(QBrush(Qt::white));
exPlot.setTitle(p.title);
exPlot.setAxisTitle(QwtPlot::xBottom, plot->axisTitle(QwtPlot::xBottom));
exPlot.setAxisTitle(QwtPlot::xTop, plot->axisTitle(QwtPlot::xTop));
exPlot.setAxisTitle(QwtPlot::yLeft, plot->axisTitle(QwtPlot::yLeft));
exPlot.setAxisTitle(QwtPlot::yRight, plot->axisTitle(QwtPlot::yRight));
QwtPlotItemList curves = plot->itemList();
/* Attach all plots from the GUI plot to the temporary plot
* Note that this will detach the plots from the GUI plot! */
QList<qreal> curvePenWidths;
for (QwtPlotItem *i : curves) {
QwtPlotCurve *c = dynamic_cast<QwtPlotCurve *>(i);
if (c != nullptr) {
QPen p = c->pen();
qreal w = p.widthF();
qreal nw;
curvePenWidths.push_back(w);
nw = w - 1.0;
if (nw < 0.0)
nw = 0.0;
p.setWidthF(nw);
c->setPen(p);
}
i->attach(&exPlot);
}
/* Scale up from millimeters to centimeters*/
QSizeF dimensionsMM(p.dimensions.width() * 10.0, p.dimensions.height() * 10.0);
/* Store current properties of the plot as we need to change them for rendering */
QFont xBottomFont = plot->axisWidget(QwtPlot::xBottom)->font();
QFont xTopFont = plot->axisWidget(QwtPlot::xTop)->font();
QFont yLeftFont = plot->axisWidget(QwtPlot::yLeft)->font();
QFont yRightFont = plot->axisWidget(QwtPlot::yRight)->font();
QFont xBottomTitleFont = plot->axisTitle(QwtPlot::xBottom).font();
QFont xTopTitleFont = plot->axisTitle(QwtPlot::xTop).font();
QFont yLeftTitleFont = plot->axisTitle(QwtPlot::yLeft).font();
QFont yRightTitleFont = plot->axisTitle(QwtPlot::yRight).font();
QFont titleFont = plot->title().font();
const qreal xBottomPenWidth = plot->axisWidget(QwtPlot::xBottom)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::xBottom)->scaleDraw()->penWidth() : 1.0;
const qreal xTopPenWidth = plot->axisWidget(QwtPlot::xTop)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::xTop)->scaleDraw()->penWidth() : 1.0;
const qreal yLeftPenWidth = plot->axisWidget(QwtPlot::yLeft)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::yLeft)->scaleDraw()->penWidth() : 1.0;
const qreal yRightPenWidth = plot->axisWidget(QwtPlot::yRight)->scaleDraw()->penWidth() > 0 ? plot->axisWidget(QwtPlot::yRight)->scaleDraw()->penWidth() : 1.0;
/* Recalculate sizes by the DPI for every element that needs it */
const qreal outputInPixels = (static_cast<qreal>(p.dimensions.width()) / 2.54) * p.dpi;
const qreal scalingRatio = (static_cast<qreal>(qApp->desktop()->logicalDpiX()) / p.dpi) * (outputInPixels / plot->geometry().width());
const qreal _xBottomPenWidth = floor((xBottomPenWidth * scalingRatio) + 0.45);
const qreal _xTopPenWidth = floor((xTopPenWidth * scalingRatio) + 0.45);
const qreal _yLeftPenWidth = floor((yLeftPenWidth * scalingRatio) + 0.45);
const qreal _yRightPenWidth = floor((yRightPenWidth * scalingRatio) + 0.45);
xBottomFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
xTopFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
yLeftFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
yRightFont.setPointSizeF(p.axisNumbersFontSize * scalingRatio);
xBottomTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
xTopTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
yLeftTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
yRightTitleFont.setPointSizeF(p.axisTitlesFontSize * scalingRatio);
titleFont.setPointSizeF(p.chartTitleFontSize * scalingRatio);
exPlot.axisWidget(QwtPlot::xBottom)->scaleDraw()->setPenWidth(_xBottomPenWidth);
exPlot.axisWidget(QwtPlot::xTop)->scaleDraw()->setPenWidth(_xTopPenWidth);
//.........这里部分代码省略.........