Ejemplo n.º 1
0
static QwtArray<QwtPicker *> activePickers(QWidget *w)
{
    QwtArray<QwtPicker *> pickers;

#if QT_VERSION >= 0x040000
    QObjectList children = w->children();
    for ( int i = 0; i < children.size(); i++ ) {
        QObject *obj = children[i];
        if ( obj->inherits("QwtPicker") ) {
            QwtPicker *picker = (QwtPicker *)obj;
            if ( picker->isEnabled() )
                pickers += picker;
        }
    }
#else
    QObjectList *children = (QObjectList *)w->children();
    if ( children ) {
        for ( QObjectListIterator it(*children); it.current(); ++it ) {
            QObject *obj = (QObject *)it.current();
            if ( obj->inherits("QwtPicker") ) {
                QwtPicker *picker = (QwtPicker *)obj;
                if ( picker->isEnabled() ) {
                    pickers.resize(pickers.size() + 1);
                    pickers[int(pickers.size()) - 1] = picker;
                }
            }
        }
    }
#endif

    return pickers;
}
void ColorMapEditor::setColorMap(const QwtLinearColorMap& map)
{
scaleColorsBox->setChecked(map.mode() == QwtLinearColorMap::ScaledColors);

QwtArray <double> colors = map.colorStops();
int rows = (int)colors.size();
table->setRowCount(rows);
table->blockSignals(true);
	
for (int i = 0; i < rows; i++)
	{
	QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val);
	double val = min_val + colors[i] * range.width();
		
	QTableWidgetItem *it = new QTableWidgetItem(QString::number(val));
    table->setItem(i, 0, it);
		
	QColor c = QColor(map.rgb(QwtDoubleInterval(0, 1), colors[i]));
	it = new QTableWidgetItem(c.name());
	it->setFlags(Qt::ItemFlags(!Qt::ItemIsEditable));
	it->setBackground(QBrush(c));
	it->setForeground(QBrush(c));
    table->setItem(i, 1, it);
	}
table->blockSignals(false);
	
color_map = map;
}
Ejemplo n.º 3
0
/*!
  Handle a mouse press event for the observed widget.

  \param me Mouse event
  \sa eventFilter(), widgetMouseReleaseEvent(),
      widgetMouseMoveEvent(),
*/
void QwtPanner::widgetMousePressEvent(QMouseEvent *me)
{
    if ( me->button() != d_data->button )
        return;

    QWidget *w = parentWidget();
    if ( w == NULL )
        return;

#if QT_VERSION < 0x040000
    if ( (me->state() & Qt::KeyButtonMask) !=
        (d_data->buttonState & Qt::KeyButtonMask) )
#else
    if ( (me->modifiers() & Qt::KeyboardModifierMask) !=
        (int)(d_data->buttonState & Qt::KeyboardModifierMask) )
#endif
    {
        return;
    }

#ifndef QT_NO_CURSOR
    showCursor(true);
#endif

    d_data->initialPos = d_data->pos = me->pos();

    QRect cr = parentWidget()->rect();
    if ( parentWidget()->inherits("QFrame") )
    {
        const QFrame* frame = (QFrame*)parentWidget();
        cr = frame->contentsRect();
    }
    setGeometry(cr);

    // We don't want to grab the picker !
    QwtArray<QwtPicker *> pickers = activePickers(parentWidget());
    for ( int i = 0; i < (int)pickers.size(); i++ )
        pickers[i]->setEnabled(false);

    d_data->pixmap = QPixmap::grabWidget(parentWidget(),
        cr.x(), cr.y(), cr.width(), cr.height());

    for ( int i = 0; i < (int)pickers.size(); i++ )
        pickers[i]->setEnabled(true);

    show();
}
void Matrix::save(const QString &fn, const QString &info, bool saveAsTemplate)
{
	QFile f(fn);
	if (!f.isOpen()){
		if (!f.open(QIODevice::Append))
			return;
	}
	bool notTemplate = !saveAsTemplate;

	QTextStream t( &f );
	t.setEncoding(QTextStream::UnicodeUTF8);
	t << "<matrix>\n";
	if (notTemplate)
        t << QString(objectName()) + "\t";
	t << QString::number(numRows())+"\t";
	t << QString::number(numCols())+"\t";
	if (notTemplate)
        t << birthDate() + "\n";
	t << info;
	t << "ColWidth\t" + QString::number(d_column_width)+"\n";
	t << "<formula>\n" + formula_str + "\n</formula>\n";
	t << "TextFormat\t" + QString(txt_format) + "\t" + QString::number(num_precision) + "\n";
	if (notTemplate)
        t << "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n";
	t << "Coordinates\t" + QString::number(x_start,'g',15) + "\t" +QString::number(x_end,'g',15) + "\t";
	t << QString::number(y_start,'g',15) + "\t" + QString::number(y_end,'g',15) + "\n";
	t << "ViewType\t" + QString::number((int)d_view_type) + "\n";
    t << "HeaderViewType\t" + QString::number((int)d_header_view_type) + "\n";

	if (d_color_map_type != Custom)
		t << "ColorPolicy\t" + QString::number(d_color_map_type) + "\n";
	else {
		t << "<ColorMap>\n";
		t << "\t<Mode>" + QString::number(d_color_map.mode()) + "</Mode>\n";
		t << "\t<MinColor>" + d_color_map.color1().name() + "</MinColor>\n";
		t << "\t<MaxColor>" + d_color_map.color2().name() + "</MaxColor>\n";
		QwtArray <double> colors = d_color_map.colorStops();
		int stops = (int)colors.size();
		t << "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n";
		for (int i = 1; i < stops - 1; i++){
			t << "\t<Stop>" + QString::number(colors[i]) + "\t";
			t << QColor(d_color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name();
			t << "</Stop>\n";
		}
		t << "</ColorMap>\n";
	}

    if (notTemplate)
        t << d_matrix_model->saveToString();
    t <<"</matrix>\n";
}
Ejemplo n.º 5
0
QString Spectrogram::saveToString()
{
QString s = "<spectrogram>\n";
s += "\t<matrix>" + QString(d_matrix->objectName()) + "</matrix>\n";

if (color_map_policy != Custom)
	s += "\t<ColorPolicy>" + QString::number(color_map_policy) + "</ColorPolicy>\n";
else
	{
	s += "\t<ColorMap>\n";
	s += "\t\t<Mode>" + QString::number(color_map.mode()) + "</Mode>\n";
	s += "\t\t<MinColor>" + color_map.color1().name() + "</MinColor>\n";
	s += "\t\t<MaxColor>" + color_map.color2().name() + "</MaxColor>\n";
	QwtArray <double> colors = color_map.colorStops();
	int stops = (int)colors.size();
	s += "\t\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n";
	for (int i = 1; i < stops - 1; i++)
		{
		s += "\t\t<Stop>" + QString::number(colors[i]) + "\t";
		s += QColor(color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name();
		s += "</Stop>\n";
		}
	s += "\t</ColorMap>\n";
	}
s += "\t<Image>"+QString::number(testDisplayMode(QwtPlotSpectrogram::ImageMode))+"</Image>\n";

bool contourLines = testDisplayMode(QwtPlotSpectrogram::ContourMode);
s += "\t<ContourLines>"+QString::number(contourLines)+"</ContourLines>\n";
if (contourLines)
	{
	s += "\t\t<Levels>"+QString::number(levels())+"</Levels>\n";
	bool defaultPen = defaultContourPen().style() != Qt::NoPen;
	s += "\t\t<DefaultPen>"+QString::number(defaultPen)+"</DefaultPen>\n";
	if (defaultPen)
		{
		s += "\t\t\t<PenColor>"+defaultContourPen().color().name()+"</PenColor>\n";
		s += "\t\t\t<PenWidth>"+QString::number(defaultContourPen().widthF())+"</PenWidth>\n";
		s += "\t\t\t<PenStyle>"+QString::number(defaultContourPen().style() - 1)+"</PenStyle>\n";
		}
	}
QwtScaleWidget *colorAxis = plot()->axisWidget(color_axis);
if (colorAxis && colorAxis->isColorBarEnabled())
	{
	s += "\t<ColorBar>\n\t\t<axis>" + QString::number(color_axis) + "</axis>\n";
	s += "\t\t<width>" + QString::number(colorAxis->colorBarWidth()) + "</width>\n";
	s += "\t</ColorBar>\n";
	}
s += "\t<Visible>"+ QString::number(isVisible()) + "</Visible>\n";
return s+"</spectrogram>\n";
}
Ejemplo n.º 6
0
QString ColorMapEditor::saveToXmlString(const QwtLinearColorMap &color_map) {
  QString s = "<ColorMap>\n";
  s += "\t<Mode>" + QString::number(color_map.mode()) + "</Mode>\n";
  s += "\t<MinColor>" + color_map.color1().name() + "</MinColor>\n";
  s += "\t<MaxColor>" + color_map.color2().name() + "</MaxColor>\n";
  QwtArray<double> colors = color_map.colorStops();
  int stops = (int)colors.size();
  s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n";
  for (int i = 1; i < stops - 1; i++) {
    s += "\t<Stop>" + QString::number(colors[i]) + "\t";
    s += QColor(color_map.rgb(QwtDoubleInterval(0, 1), colors[i])).name();
    s += "</Stop>\n";
  }
  return s += "</ColorMap>\n";
}
Ejemplo n.º 7
0
QString LinearColorMap::toXmlString()
{
	QString s = "<ColorMap>\n";
	s += "\t<Mode>" + QString::number(mode()) + "</Mode>\n";
	s += "\t<MinColor>" + color1().name() + "</MinColor>\n";
	s += "\t<MaxColor>" + color2().name() + "</MaxColor>\n";
	if (d_range.isValid())
		s += "\t<Range>" + QString::number(d_range.minValue(), 'g', 15) + "\t" + QString::number(d_range.maxValue(), 'g', 15) + "</Range>\n";
	QwtArray <double> colors = colorStops();
	int stops = (int)colors.size();
	s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n";
	for (int i = 1; i < stops - 1; i++){
		s += "\t<Stop>" + QString::number(colors[i], 'g', 15) + "\t";
		s += color(i).name();
		s += "</Stop>\n";
	}
	return s += "</ColorMap>\n";
}
Ejemplo n.º 8
0
QString Matrix::saveToString(const QString &info, bool saveAsTemplate)
{
    bool notTemplate = !saveAsTemplate;
	QString s = "<matrix>\n";
	if (notTemplate)
        s += QString(objectName()) + "\t";
	s += QString::number(numRows())+"\t";
	s += QString::number(numCols())+"\t";
	if (notTemplate)
        s += birthDate() + "\n";
	s += info;
	s += "ColWidth\t" + QString::number(d_column_width)+"\n";
	s += "<formula>\n" + formula_str + "\n</formula>\n";
	s += "TextFormat\t" + QString(txt_format) + "\t" + QString::number(num_precision) + "\n";
	if (notTemplate)
        s += "WindowLabel\t" + windowLabel() + "\t" + QString::number(captionPolicy()) + "\n";
	s += "Coordinates\t" + QString::number(x_start,'g',15) + "\t" +QString::number(x_end,'g',15) + "\t";
	s += QString::number(y_start,'g',15) + "\t" + QString::number(y_end,'g',15) + "\n";
	s += "ViewType\t" + QString::number((int)d_view_type) + "\n";
    s += "HeaderViewType\t" + QString::number((int)d_header_view_type) + "\n";

	if (d_color_map_type != Custom)
		s += "ColorPolicy\t" + QString::number(d_color_map_type) + "\n";
	else {
		s += "<ColorMap>\n";
		s += "\t<Mode>" + QString::number(d_color_map.mode()) + "</Mode>\n";
		s += "\t<MinColor>" + d_color_map.color1().name() + "</MinColor>\n";
		s += "\t<MaxColor>" + d_color_map.color2().name() + "</MaxColor>\n";
		QwtArray <double> colors = d_color_map.colorStops();
		int stops = (int)colors.size();
		s += "\t<ColorStops>" + QString::number(stops - 2) + "</ColorStops>\n";
		for (int i = 1; i < stops - 1; i++){
			s += "\t<Stop>" + QString::number(colors[i]) + "\t";
			s += QColor(d_color_map.rgb(QwtDoubleInterval(0,1), colors[i])).name();
			s += "</Stop>\n";
		}
		s += "</ColorMap>\n";
	}

    if (notTemplate)
        s += d_matrix_model->saveToString();
    s +="</matrix>\n";
	return s;
}
Ejemplo n.º 9
0
void ColorMapEditor::setColorMap(const QwtLinearColorMap& map)
{
  scaleColorsBox->setChecked(map.mode() == QwtLinearColorMap::ScaledColors);

  QwtArray <double> colors = map.colorStops();
  int rows = (int)colors.size();
  table->setRowCount(rows);
  table->blockSignals(true);

  QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val);
  for (int i = 0; i < rows; i++){
    DoubleSpinBox *sb = new DoubleSpinBox();
    sb->setLocale(d_locale);
    sb->setDecimals(d_precision);
    sb->setValue(min_val + colors[i] * range.width());

    if (i == 0)
      sb->setRange(min_val, min_val);
    else if (i == rows -1)
      sb->setRange(max_val, max_val);
    else
      sb->setRange(min_val, max_val);

    connect(sb, SIGNAL(valueChanged(double)), this, SLOT(updateColorMap()));
    connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *)));
    table->setCellWidget(i, 0, sb);

    QColor c = QColor(map.rgb(QwtDoubleInterval(0, 1), colors[i]));
    QTableWidgetItem *it = new QTableWidgetItem(c.name());
// Avoid compiler warning
//#ifdef Q_CC_MSVC
    it->setFlags(it->flags() & (~Qt::ItemIsEditable));
//#else
//    it->setFlags(!Qt::ItemIsEditable);
//#endif
    it->setBackground(QBrush(c));
    it->setForeground(QBrush(c));
    table->setItem(i, 1, it);
  }
  table->blockSignals(false);

  color_map = map;
}
Ejemplo n.º 10
0
/*!
  Draw circles

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radialMap Maps radius values into painter coordinates.
  \param values Radial values, indicating the distances from the pole
*/
void QwtPolarGrid::drawCircles(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, const QwtScaleMap &radialMap,
  const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    const double val = values[i];

    const GridData &gridData =
      d_data->gridData[QwtPolar::Radius];

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth];
      if ( axis.isVisible &&
           axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) )
      {
#if QWT_VERSION < 0x050200
        if ( isClose( val, gridData.scaleDiv.hBound() ) )
#else
        if ( isClose( val, gridData.scaleDiv.upperBound() ) )
#endif
          skipLine = true;
      }
    }

#if QWT_VERSION < 0x050200
    if ( isClose( val, gridData.scaleDiv.lBound() ) )
#else
    if ( isClose( val, gridData.scaleDiv.lowerBound() ) )
#endif
      skipLine = true;

    if ( !skipLine )
    {
      const double radius = radialMap.transform( val );

      QwtDoubleRect outerRect( 0, 0, 2 * radius, 2 * radius );
      outerRect.moveCenter( pole );

#if QT_VERSION < 0x040000
      QwtPainter::drawEllipse( painter, outerRect.toRect() );
#else
      if ( testDisplayFlag( ClipGridLines ) )
      {

        /*
            Qt4 is horrible slow, when painting primitives,
            with coordinates far outside the visible area.
            We need to clip.
        */

        const QwtArray<QwtDoubleInterval> angles =
          QwtClipper::clipCircle( canvasRect, pole, radius );
        for ( int i = 0; i < angles.size(); i++ )
        {
          const QwtDoubleInterval intv = angles[i];
          if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI )
            QwtPainter::drawEllipse( painter, outerRect.toRect() );
          else
          {
            const double from = intv.minValue() / M_PI * 180;
            const double to = intv.maxValue() / M_PI * 180;
            double span = to - from;
            if ( span < 0.0 )
              span += 360.0;

            const QwtMetricsMap &mm = QwtPainter::metricsMap();
            const QRect r = outerRect.toRect();

            painter->drawArc( mm.layoutToDevice( r, painter ),
                              qRound( from * 16 ), qRound( span * 16 ) );
          }

        }
      }
      else
      {
        QwtPainter::drawEllipse( painter, outerRect.toRect() );
      }
#endif
    }
  }
}