void ColorMapEditor::validateLevel(int row, int col) { if (col) return; if (row == 0 || row == table->rowCount() - 1) { QMessageBox::critical(this, tr("Input Error"), tr("Sorry, you cannot edit this value!")); table->blockSignals(true); if (!row) table->item(0, 0)->setText(QString::number(min_val)); else table->item(row, 0)->setText(QString::number(max_val)); table->blockSignals(false); return; } bool user_input_error = false; QString s = table->item(row, 0)->text().remove("-").remove(".").remove(",").remove("+"); if (s.isEmpty() || s.contains(QRegExp("\\D"))) { QMessageBox::critical(this, tr("Input Error"), tr("Please enter a valid color level value!")); user_input_error = true; } QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val); double val = table->item(row, 0)->text().replace(",", ".").toDouble(); if (!range.contains (val) || user_input_error) { QwtArray<double> colors = color_map.colorStops(); val = min_val + colors[row] * range.width(); table->blockSignals(true); table->item(row, 0)->setText(QString::number(val)); table->blockSignals(false); } }
const QList<double> &levels, int flags) const #else QwtRasterData::ContourLines QwtRasterData::contourLines( const QwtDoubleRect &rect, const QSize &raster, const QValueList<double> &levels, int flags) const #endif { ContourLines contourLines; if ( levels.size() == 0 || !rect.isValid() || !raster.isValid() ) return contourLines; const double dx = rect.width() / raster.width(); const double dy = rect.height() / raster.height(); const bool ignoreOnPlane = flags & QwtRasterData::IgnoreAllVerticesOnLevel; const QwtDoubleInterval range = this->range(); bool ignoreOutOfRange = false; if ( range.isValid() ) ignoreOutOfRange = flags & IgnoreOutOfRange; ((QwtRasterData*)this)->initRaster(rect, raster); for ( int y = 0; y < raster.height() - 1; y++ ) { enum Position { Center, TopLeft, TopRight, BottomRight, BottomLeft, NumPositions }; Contour3DPoint xy[NumPositions]; for ( int x = 0; x < raster.width() - 1; x++ ) { const QwtDoublePoint pos(rect.x() + x * dx, rect.y() + y * dy); if ( x == 0 ) { xy[TopRight].setPos(pos.x(), pos.y()); xy[TopRight].setZ( value( xy[TopRight].x(), xy[TopRight].y()) ); xy[BottomRight].setPos(pos.x(), pos.y() + dy); xy[BottomRight].setZ( value(xy[BottomRight].x(), xy[BottomRight].y()) ); } xy[TopLeft] = xy[TopRight]; xy[BottomLeft] = xy[BottomRight]; xy[TopRight].setPos(pos.x() + dx, pos.y()); xy[BottomRight].setPos(pos.x() + dx, pos.y() + dy); xy[TopRight].setZ( value(xy[TopRight].x(), xy[TopRight].y()) ); xy[BottomRight].setZ( value(xy[BottomRight].x(), xy[BottomRight].y()) ); double zMin = xy[TopLeft].z(); double zMax = zMin; double zSum = zMin; for ( int i = TopRight; i <= BottomLeft; i++ ) { const double z = xy[i].z(); zSum += z; if ( z < zMin ) zMin = z; if ( z > zMax ) zMax = z; } if ( ignoreOutOfRange ) { if ( !range.contains(zMin) || !range.contains(zMax) ) continue; } if ( zMax < levels[0] || zMin > levels[levels.size() - 1] ) { continue; } xy[Center].setPos(pos.x() + 0.5 * dx, pos.y() + 0.5 * dy); xy[Center].setZ(0.25 * zSum); const int numLevels = (int)levels.size(); for (int l = 0; l < numLevels; l++) { const double level = levels[l]; if ( level < zMin || level > zMax ) continue; #if QT_VERSION >= 0x040000 QPolygonF &lines = contourLines[level]; #else QwtArray<QwtDoublePoint> &lines = contourLines[level]; #endif const ContourPlane plane(level); QwtDoublePoint line[2]; Contour3DPoint vertex[3]; for (int m = TopLeft; m < NumPositions; m++) { vertex[0] = xy[m]; vertex[1] = xy[0]; vertex[2] = xy[m != BottomLeft ? m + 1 : TopLeft]; const bool intersects = plane.intersect(vertex, line, ignoreOnPlane); if ( intersects ) { #if QT_VERSION >= 0x040000 lines += line[0]; lines += line[1]; #else const int index = lines.size(); lines.resize(lines.size() + 2, QGArray::SpeedOptim); lines[index] = line[0]; lines[index+1] = line[1]; #endif } } } } } ((QwtRasterData*)this)->discardRaster(); return contourLines; }