/** * Draw widget contents on screen * @param event event info */ void ColorButton::paintEvent(QPaintEvent *e) { // this is based on QtColorButton from Qt tools source QToolButton::paintEvent(e); const int pixSize = 10; QBrush br(color()); if (_setAlpha) { QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, color()); br = QBrush(pm); } QPainter p(this); const int corr = 4; QRect r = rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); p.fillRect(r, br); const QColor frameColor1(0, 0, 0, 26); p.setPen(frameColor1); p.drawRect(r.adjusted(1, 1, -2, -2)); const QColor frameColor2(0, 0, 0, 51); p.setPen(frameColor2); p.drawRect(r.adjusted(0, 0, -1, -1)); }
QPixmap QtGradientUtils::gradientPixmap(const QGradient &gradient, const QSize &size, bool checkeredBackground) { QImage image(size, QImage::Format_ARGB32); QPainter p(&image); p.setCompositionMode(QPainter::CompositionMode_Source); if (checkeredBackground) { int pixSize = 20; QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); p.setBrushOrigin((size.width() % pixSize + pixSize) / 2, (size.height() % pixSize + pixSize) / 2); p.fillRect(0, 0, size.width(), size.height(), pm); p.setBrushOrigin(0, 0); p.setCompositionMode(QPainter::CompositionMode_SourceOver); } const qreal scaleFactor = 0.999999; p.scale(scaleFactor, scaleFactor); QGradient grad = gradient; grad.setCoordinateMode(QGradient::StretchToDeviceMode); p.fillRect(QRect(0, 0, size.width(), size.height()), grad); p.drawRect(QRect(0, 0, size.width() - 1, size.height() - 1)); return QPixmap::fromImage(image); }
QIcon iconForColor(const QColor &color) { QPixmap pix(6, 6); int pixSize = 20; QBrush br(color); QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, color); br = QBrush(pm); QPainter p(&pix); int corr = 1; QRect r = pix.rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); p.fillRect(r, br); p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, r.width() / 2, r.height() / 2, QColor(color.rgb())); p.drawRect(pix.rect().adjusted(0, 0, -1, -1)); return pix; }
QPixmap QtColorButtonPrivate::generatePixmap() const { QPixmap pix(24, 24); int pixSize = 20; QBrush br(shownColor()); QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, shownColor()); br = QBrush(pm); QPainter p(&pix); int corr = 1; QRect r = pix.rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); p.fillRect(r, br); p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, r.width() / 2, r.height() / 2, QColor(shownColor().rgb())); p.drawRect(pix.rect().adjusted(0, 0, -1, -1)); return pix; }
GradientStopEditor::GradientStopEditor( StopChannel _stopChannel, QWidget *parent ): QWidget( parent ), stopChannel( _stopChannel ), pointPen( QPen( QColor( 255, 255, 255, 191 ), 1 ) ), connectionPen( QPen( QColor( 255, 255, 255, 127 ), 2 ) ), pointBrush( QBrush( QColor( 191, 191, 191, 127 ) ) ), linesPen( QColor( 120, 120, 120, 150 ), 5 ), compositeGradient( 0, 0, width(), 0 ), currentMovedStop( -1 ) { stopChannel = _stopChannel; values << 0 << 255; positions << 0 << 1; if( stopChannel == composite ) { QPixmap pm( 20, 20 ); QPainter pmp( &pm ); pmp.fillRect( 0, 0, 10, 10, Qt::lightGray ); pmp.fillRect( 10, 10, 10, 10, Qt::lightGray ); pmp.fillRect( 0, 10, 10, 10, Qt::darkGray ); pmp.fillRect( 10, 0, 10, 10, Qt::darkGray ); pmp.end(); QPalette pal = palette(); pal.setBrush( backgroundRole(), QBrush( pm ) ); setAutoFillBackground( true ); setPalette( pal ); } else setAttribute( Qt::WA_NoBackground ); }
QtGradientView::QtGradientView(QWidget *parent) : QWidget(parent) { m_manager = 0; m_ui.setupUi(this); m_ui.listWidget->setViewMode(QListView::IconMode); m_ui.listWidget->setMovement(QListView::Static); m_ui.listWidget->setTextElideMode(Qt::ElideRight); m_ui.listWidget->setResizeMode(QListWidget::Adjust); m_ui.listWidget->setIconSize(QSize(64, 64)); m_ui.listWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); QPalette pal = m_ui.listWidget->viewport()->palette(); int pixSize = 18; QPixmap pm(2 * pixSize, 2 * pixSize); QColor c1 = palette().color(QPalette::Midlight); QColor c2 = palette().color(QPalette::Dark); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, c1); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, c1); pmp.fillRect(0, pixSize, pixSize, pixSize, c2); pmp.fillRect(pixSize, 0, pixSize, pixSize, c2); pal.setBrush(QPalette::Base, QBrush(pm)); m_ui.listWidget->viewport()->setPalette(pal); connect(m_ui.listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotGradientActivated(QListWidgetItem*))); connect(m_ui.listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotRenameGradient(QListWidgetItem*))); connect(m_ui.listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(slotCurrentItemChanged(QListWidgetItem*))); m_newAction = new QAction(QIcon(QLatin1String(":/trolltech/qtgradienteditor/images/plus.png")), tr("New..."), this); m_editAction = new QAction(QIcon(QLatin1String(":/trolltech/qtgradienteditor/images/edit.png")), tr("Edit..."), this); m_renameAction = new QAction(tr("Rename"), this); m_removeAction = new QAction(QIcon(QLatin1String(":/trolltech/qtgradienteditor/images/minus.png")), tr("Remove"), this); connect(m_newAction, SIGNAL(triggered()), this, SLOT(slotNewGradient())); connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditGradient())); connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveGradient())); connect(m_renameAction, SIGNAL(triggered()), this, SLOT(slotRenameGradient())); m_ui.listWidget->addAction(m_newAction); m_ui.listWidget->addAction(m_editAction); m_ui.listWidget->addAction(m_renameAction); m_ui.listWidget->addAction(m_removeAction); m_ui.newButton->setDefaultAction(m_newAction); m_ui.editButton->setDefaultAction(m_editAction); m_ui.renameButton->setDefaultAction(m_renameAction); m_ui.removeButton->setDefaultAction(m_removeAction); m_ui.listWidget->setContextMenuPolicy(Qt::ActionsContextMenu); }
// ========================================================================= Pruning_table_mp_cp:: Pruning_table_mp_cp(Transform_table *tr, Turn_table *tn, int e1, int c1): e1(e1), c1(c1) // ------------------------------------------------------------------------- { int n, d, mx = 0; int mp, cp, t; unsigned int sm = 0; Pack_mp pmp(e1); int Nmp = pmp.len(); int Smp = pmp.startlen(); Pack_cp pcp(c1); int Ncp = pcp.len(); int Scp = pcp.startlen(); for (mp = 0; mp < Nmp; mp++) for (cp = 0; cp < Ncp; cp++) a[mp][cp] = BIG; for (t = 0; t < B_N_TW; t++) if (mx < tn->b_len(t)) mx = tn->b_len(t); fprintf(stderr, "\n - middle edge permutations - corner permutations (phase 2, %i x %i goal/s):\n", Smp, Scp); for (mp = 0; mp < Smp; mp++) for (cp = 0; cp < Scp; cp++) a[pmp.start(mp)][pcp.start(cp)] = 0; d = 0; n = Smp * Scp; while (n) { fprintf(stderr," %2i %8i %10u\n", d, n, sm += n); n = 0; d++; for (mp = 0; mp < Nmp; mp++) { for (cp = 0; cp < Ncp; cp++) { if (d <= a[mp][cp] || d > a[mp][cp] + mx) continue; for (t = 0; t < B_N_TW; t++) { if (d == a[mp][cp] + tn->b_len(t)) { int nmp = tr->mp->b_do_tw(t, mp); int ncp = tr->cp->b_do_tw(t, cp); if (a[nmp][ncp] > d) { a[nmp][ncp] = d; n++; } } } } } } }
// ========================================================================= Pruning_table_mp_ep:: Pruning_table_mp_ep(Transform_table *tr, Turn_table *tn, int e1): e1(e1) // ------------------------------------------------------------------------- { int n, d, mx = 0; int mp, ep, t; unsigned int sm = 0; Pack_mp pmp(e1); int Nmp = pmp.len(); int Smp = pmp.startlen(); Pack_ep pep(e1); int Nep = pep.len(); int Sep = pep.startlen(); for (mp = 0; mp < Nmp; mp++) for (ep = 0; ep < Nep; ep++) a[mp][ep] = BIG; for (t = 0; t < B_N_TW; t++) if (mx < tn->b_len(t)) mx = tn->b_len(t); fprintf(stderr, "\n - middle edge - updown edge permutations (phase 2, %i x %i):\n", Smp, Sep); for (mp = 0; mp < Smp; mp++) for (ep = 0; ep < Sep; ep++) a[pmp.start(mp)][pep.start(ep)] = 0; d = 0; n = Smp * Sep; while (n) { fprintf(stderr," %2i %8i %10u\n", d, n, sm += n); n = 0; d++; for (mp = 0; mp < Nmp; mp++) { for (ep = 0; ep < Nep; ep++) { if (d <= a[mp][ep] || d > a[mp][ep] + mx) continue; for (t = 0; t < B_N_TW; t++) { if (d == a[mp][ep] + tn->b_len(t)) { int nmp = tr->mp->b_do_tw(t, mp); int nep = tr->ep->b_do_tw(t, ep); if (a[nmp][nep] > d) { a[nmp][nep] = d; n++; } } } } } } }
void QtColorButton::paintEvent(QPaintEvent *event) { QToolButton::paintEvent(event); if (!isEnabled()) return; const int pixSize = 10; QBrush br(d_ptr->shownColor()); if (d_ptr->m_backgroundCheckered) { QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, d_ptr->shownColor()); br = QBrush(pm); } QPainter p(this); const int corr = 4; QRect r = rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); p.fillRect(r, br); //const int adjX = qRound(r.width() / 4.0); //const int adjY = qRound(r.height() / 4.0); //p.fillRect(r.adjusted(adjX, adjY, -adjX, -adjY), // QColor(d_ptr->shownColor().rgb())); /* p.fillRect(r.adjusted(0, r.height() * 3 / 4, 0, 0), QColor(d_ptr->shownColor().rgb())); p.fillRect(r.adjusted(0, 0, 0, -r.height() * 3 / 4), QColor(d_ptr->shownColor().rgb())); */ /* const QColor frameColor0(0, 0, 0, qRound(0.2 * (0xFF - d_ptr->shownColor().alpha()))); p.setPen(frameColor0); p.drawRect(r.adjusted(adjX, adjY, -adjX - 1, -adjY - 1)); */ const QColor frameColor1(0, 0, 0, 26); p.setPen(frameColor1); p.drawRect(r.adjusted(1, 1, -2, -2)); const QColor frameColor2(0, 0, 0, 51); p.setPen(frameColor2); p.drawRect(r.adjusted(0, 0, -1, -1)); }
PredicateMask& getPredicateMask(ID forID, RegistryPtr reg) { auto it = predMasks.find(forID); if( it == predMasks.end() ) { PredicateMaskPtr pmp(new PredicateMask); pmp->setRegistry(reg); pmp->addPredicate(forID); predMasks.insert(std::make_pair(forID, pmp)); return *pmp; } else { return *it->second; } }
void tst_QVolatileImage::paint() { #ifdef Q_OS_SYMBIAN QVolatileImage img(100, 100, QImage::Format_ARGB32); img.beginDataAccess(); img.imageRef().fill(QColor(Qt::green).rgba()); QPainter p(&img.imageRef()); p.drawRect(10, 10, 50, 50); p.end(); img.endDataAccess(); QImage imgA = img.toImage(); // The following assumes that on openvg the pixmapdata is backed by QVolatileImage) // (and that openvg is in use) // It should pass with any engine nonetheless. // See if painting into the underlying QImage succeeds. QPixmap pm(100, 100); if (pm.paintEngine()->type() == QPaintEngine::Raster) { pm.fill(Qt::green); QPainter pmp(&pm); pmp.drawRect(10, 10, 50, 50); pmp.end(); QImage imgB = pm.toImage(); QVERIFY(fuzzyCompareImages(imgA, imgB, 0)); // Exercise the accelerated QVolatileImagePaintEngine::drawPixmap() a bit. QPixmap targetPm(pm.size()); targetPm.fill(Qt::black); pmp.begin(&targetPm); pmp.drawPixmap(QPointF(0, 0), pm); pmp.end(); imgB = targetPm.toImage(); QVERIFY(fuzzyCompareImages(imgA, imgB, 0)); // Now the overload taking rects. targetPm.fill(Qt::black); pmp.begin(&targetPm); QRectF rect(QPointF(0, 0), pm.size()); pmp.drawPixmap(rect, pm, rect); pmp.end(); imgB = targetPm.toImage(); QVERIFY(fuzzyCompareImages(imgA, imgB, 0)); } else { QSKIP("Pixmaps not painted via raster, skipping paint test", SkipSingle); } #endif }
void PaintWidget::doViewportTransparent() { QPixmap pm( 20, 20 ); QPainter pmp( &pm ); pmp.fillRect( 0, 0, 10, 10, Qt::lightGray ); pmp.fillRect(10, 10, 10, 10, Qt::lightGray ); pmp.fillRect( 0, 10, 10, 10, Qt::darkGray ); pmp.fillRect( 10, 0, 10, 10, Qt::darkGray ); pmp.end(); QPalette pal = palette(); pal.setBrush( backgroundRole(), QBrush( pm ) ); setAutoFillBackground( true ); setPalette( pal ); transparent = true; update(); }
GradientRangeEditor::GradientRangeEditor( QWidget *parent ):QWidget( parent ), pointPen( QPen( QColor( 255, 255, 255, 191 ), 1 ) ), pointBrush( QBrush( QColor( 191, 191, 191, 127 ) ) ), movedPoint( nothingMoved ) { QPixmap pm( 20, 20 ); QPainter pmp( &pm ); pmp.fillRect( 0, 0, 10, 10, Qt::lightGray ); pmp.fillRect( 10, 10, 10, 10, Qt::lightGray ); pmp.fillRect( 0, 10, 10, 10, Qt::darkGray ); pmp.fillRect( 10, 0, 10, 10, Qt::darkGray ); pmp.end(); QPalette pal = palette(); pal.setBrush( backgroundRole(), QBrush( pm ) ); setAutoFillBackground( true ); setPalette( pal ); setGradient( QLinearGradient( QPointF( 0.1, 0.1 ), QPointF( 0.9, 0.9 ) ) ); setMinimumSize( QSize( 64, 64 ) ); }
ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent) : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0)) { // Checkers background if (m_shade_type == ARGBShade) { QPixmap pm(20, 20); QPainter pmp(&pm); pmp.fillRect(0, 0, 10, 10, Qt::lightGray); pmp.fillRect(10, 10, 10, 10, Qt::lightGray); pmp.fillRect(0, 10, 10, 10, Qt::darkGray); pmp.fillRect(10, 0, 10, 10, Qt::darkGray); pmp.end(); QPalette pal = palette(); pal.setBrush(backgroundRole(), QBrush(pm)); setAutoFillBackground(true); setPalette(pal); } else { setAttribute(Qt::WA_NoBackground); } QPolygonF points; points << QPointF(0, sizeHint().height()) << QPointF(sizeHint().width(), 0); m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape); // m_hoverPoints->setConnectionType(HoverPoints::LineConnection); m_hoverPoints->setPoints(points); m_hoverPoints->setPointLock(0, HoverPoints::LockToLeft); m_hoverPoints->setPointLock(1, HoverPoints::LockToRight); m_hoverPoints->setSortType(HoverPoints::XSort); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect(m_hoverPoints, SIGNAL(pointsChanged(QPolygonF)), this, SIGNAL(colorsChanged())); }
void Widget_ColorButton::paintEvent(QPaintEvent *) { // paint button here QStylePainter p(this); QStyleOptionButton opt; initStyleOption(&opt); p.drawControl(QStyle::CE_PushButton, opt); if (!isEnabled()) return; const int pixSize = 10; QBrush br(m_color); { QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, m_color); br = QBrush(pm); } const int corr = 5; QRect r = rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / corr); p.fillRect(r, br); const QColor frameColor1(0, 0, 0, 26); p.setPen(frameColor1); p.drawRect(r.adjusted(1, 1, -2, -2)); const QColor frameColor2(0, 0, 0, 51); p.setPen(frameColor2); p.drawRect(r.adjusted(0, 0, -1, -1)); }
void QtGradientWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e) QPainter p(this); if (d_ptr->m_backgroundCheckered) { int pixSize = 40; QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); p.setBrushOrigin((size().width() % pixSize + pixSize) / 2, (size().height() % pixSize + pixSize) / 2); p.fillRect(rect(), pm); p.setBrushOrigin(0, 0); } QGradient *gradient = 0; switch (d_ptr->m_gradientType) { case QGradient::LinearGradient: gradient = new QLinearGradient(d_ptr->m_startLinear, d_ptr->m_endLinear); break; case QGradient::RadialGradient: gradient = new QRadialGradient(d_ptr->m_centralRadial, d_ptr->m_radiusRadial, d_ptr->m_focalRadial); break; case QGradient::ConicalGradient: gradient = new QConicalGradient(d_ptr->m_centralConical, d_ptr->m_angleConical); break; default: break; } if (!gradient) return; gradient->setStops(d_ptr->m_gradientStops); gradient->setSpread(d_ptr->m_gradientSpread); p.save(); p.scale(size().width(), size().height()); p.fillRect(QRect(0, 0, 1, 1), *gradient); p.restore(); p.setRenderHint(QPainter::Antialiasing); QColor c = QColor::fromRgbF(0.5, 0.5, 0.5, 0.5); QBrush br(c); p.setBrush(br); QPen pen(Qt::white); pen.setWidthF(1); p.setPen(pen); QPen dragPen = pen; dragPen.setWidthF(2); if (d_ptr->m_gradientType == QGradient::LinearGradient) { p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_startLinear, d_ptr->m_handleSize); p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_endLinear, d_ptr->m_handleSize); p.restore(); } else if (d_ptr->m_gradientType == QGradient::RadialGradient) { QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial); p.save(); QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3); QRectF r1(0, r.y(), size().width(), r.height()); QRectF r2(r.x(), 0, r.width(), r.y()); QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height()); p.fillRect(r1, c); p.fillRect(r2, c); p.fillRect(r3, c); p.setBrush(Qt::NoBrush); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralRadial, d_ptr->m_handleSize); p.restore(); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial * size().width(), central.y() - d_ptr->m_radiusRadial * size().height(), 2 * d_ptr->m_radiusRadial * size().width(), 2 * d_ptr->m_radiusRadial * size().height()); p.setClipRect(r1); p.setClipRect(r2, Qt::UniteClip); p.setClipRect(r3, Qt::UniteClip); p.drawEllipse(rect); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) { p.save(); p.setPen(dragPen); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), central.y() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height()); p.drawEllipse(rect); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::FocalRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_focalRadial, 2 * d_ptr->m_handleSize / 3); p.restore(); } else if (d_ptr->m_gradientType == QGradient::ConicalGradient) { double radius = size().width(); if (size().height() < radius) radius = size().height(); radius /= 2; double corr = d_ptr->m_handleSize / 3; radius -= corr; QPointF central = d_ptr->toViewport(d_ptr->m_centralConical); p.save(); p.setBrush(Qt::NoBrush); QPen pen2(c); pen2.setWidthF(2 * d_ptr->m_handleSize / 3); p.setPen(pen2); p.drawEllipse(d_ptr->pointRect(central, 2 * radius)); p.restore(); p.save(); p.setBrush(Qt::NoBrush); int pointCount = 2; for (int i = 0; i < pointCount; i++) { QPointF ang(cos(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().width() / 2, -sin(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.drawLine(QPointF(central.x() - ang.x() * (radius - corr) / mod, central.y() - ang.y() * (radius - corr) / mod), QPointF(central.x() - ang.x() * (radius + corr) / mod, central.y() - ang.y() * (radius + corr) / mod)); } if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::AngleConicalHandle) { p.save(); p.setPen(dragPen); QPointF ang(cos(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().width() / 2, -sin(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralConicalHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralConical, d_ptr->m_handleSize); p.restore(); } delete gradient; }
scannerwindow::scannerwindow(QList<int> parameters, QMainWindow *parent, bool load, QTextStream* stream): QObject(parent) { this->parameters=parameters; widget = new QWidget(); widget->setAttribute(Qt::WA_DeleteOnClose); graph = new Q3DSurface(); container = QWidget::createWindowContainer(graph, widget); container->setAttribute(Qt::WA_AcceptTouchEvents); widget->setGeometry( QStyle::alignedRect( Qt::LeftToRight, Qt::AlignTop, widget->size(), qApp->desktop()->availableGeometry() ) ); bitmapForward=new QCustomPlot(widget); bitmapBackward=new QCustomPlot(widget); bitmapCombined=new QCustomPlot(widget); bitmapForward->setContextMenuPolicy(Qt::CustomContextMenu); bitmapBackward->setContextMenuPolicy(Qt::CustomContextMenu); bitmapCombined->setContextMenuPolicy(Qt::CustomContextMenu); bitmapBackward->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); bitmapForward->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); bitmapCombined->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); initializeBitmapForward(bitmapForward); initializeBitmapBackward(bitmapBackward); initializeBitmapCombined(bitmapCombined); if (!graph->hasContext()) { QMessageBox msgBox; msgBox.setText("Couldn't initialize the OpenGL context."); msgBox.exec(); } QSize screenSize = graph->screen()->size(); container->setMinimumSize(QSize(screenSize.width() / 3, screenSize.height()/4)); container->setMaximumSize(screenSize); container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); container->setFocusPolicy(Qt::StrongFocus); bitmapBackward->setMinimumSize(screenSize.width()/4, screenSize.height()/4); bitmapForward->setMinimumSize(screenSize.width()/4, screenSize.height()/4); bitmapCombined->setMinimumSize(screenSize.width()/4, screenSize.height()/4); QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); QSplitter *hSplitterMain = new QSplitter(); QSplitter *vSplitterRight = new QSplitter(); hLayout->setSizeConstraint(QBoxLayout::SizeConstraint::SetMinimumSize); vSplitterRight->addWidget(bitmapForward); vSplitterRight->addWidget(bitmapBackward); vSplitterRight->addWidget(bitmapCombined); vSplitterRight->setOrientation(Qt::Orientation::Vertical); vSplitterRight->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); hSplitterMain->setOrientation(Qt::Orientation::Horizontal); hSplitterMain->addWidget(container); hSplitterMain->addWidget(vSplitterRight); hSplitterMain->setStyleSheet("QSplitter::handle {background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,stop:0 rgba(255, 255, 255, 0),stop:0.407273 rgba(200, 200, 200, 255),stop:0.4825 rgba(101, 104, 113, 235), stop:0.6 rgba(255, 255, 255, 0));}"); vSplitterRight->setStyleSheet("QSplitter::handle {background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,stop:0 rgba(255, 255, 255, 0),stop:0.407273 rgba(200, 200, 200, 255),stop:0.4825 rgba(101, 104, 113, 235), stop:0.6 rgba(255, 255, 255, 0));}"); hLayout->addWidget(hSplitterMain); hLayout->addLayout(vLayout); vLayout->setAlignment(Qt::AlignTop); widget->setWindowTitle(QStringLiteral("AFM Scan")); QGroupBox *modelGroupBox = new QGroupBox(QStringLiteral("Scan")); if(!load){ AFM_Scan_3D_RB = new QPushButton(widget); AFM_Scan_3D_RB->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); AFM_Scan_3D_RB->setText(QStringLiteral("Start Scan")); AFM_Scan_3D_RB->setCheckable(true); AFM_Scan_3D_RB->setChecked(false); } SaveSurface = new QPushButton(widget); SaveSurface->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); SaveSurface->setText(QStringLiteral("Save Data")); BitmapView = new QPushButton(widget); BitmapView->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); BitmapView->setText(QStringLiteral("Save BMP")); QVBoxLayout *modelVBox = new QVBoxLayout; if(!load){ modelVBox->addWidget(AFM_Scan_3D_RB); } modelVBox->addWidget(BitmapView); modelVBox->addWidget(SaveSurface); modelGroupBox->setLayout(modelVBox); QGroupBox *selectionGroupBox = new QGroupBox(QStringLiteral("Selection Mode")); selectionGroupBox->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); QCheckBox *piezoMove = new QCheckBox(widget); piezoMove->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); piezoMove->setText(QStringLiteral("Piezo")); piezoMove->setChecked(true); modelVBox->addWidget(piezoMove); QRadioButton *modeNoneRB = new QRadioButton(widget); modeNoneRB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); modeNoneRB->setText(QStringLiteral("No selection")); modeNoneRB->setChecked(false); QRadioButton *modeItemRB = new QRadioButton(widget); modeItemRB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); modeItemRB->setText(QStringLiteral("Item")); modeItemRB->setChecked(false); QRadioButton *modeSliceRowRB = new QRadioButton(widget); modeSliceRowRB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); modeSliceRowRB->setText(QStringLiteral("Row Slice")); modeSliceRowRB->setChecked(false); QRadioButton *modeSliceColumnRB = new QRadioButton(widget); modeSliceColumnRB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); modeSliceColumnRB->setText(QStringLiteral("Column Slice")); modeSliceColumnRB->setChecked(false); QVBoxLayout *selectionVBox = new QVBoxLayout; selectionVBox->addWidget(modeNoneRB); selectionVBox->addWidget(modeItemRB); selectionVBox->addWidget(modeSliceRowRB); selectionVBox->addWidget(modeSliceColumnRB); selectionGroupBox->setLayout(selectionVBox); QSlider *axisCameraSliderZ = new QSlider(Qt::Horizontal, widget); axisCameraSliderZ->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); axisCameraSliderZ->setMinimum(0); axisCameraSliderZ->setMaximum(179); axisCameraSliderZ->setTickInterval(1); axisCameraSliderZ->setEnabled(true); QSlider *axisCameraSliderY = new QSlider(Qt::Horizontal, widget); axisCameraSliderY->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); axisCameraSliderY->setMinimum(0); axisCameraSliderY->setMaximum(180); axisCameraSliderY->setTickInterval(0); axisCameraSliderY->setEnabled(true); QComboBox *themeList = new QComboBox(widget); themeList->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); themeList->addItem(QStringLiteral("Qt")); themeList->addItem(QStringLiteral("Primary Colors")); themeList->addItem(QStringLiteral("Digia")); themeList->addItem(QStringLiteral("Stone Moss")); themeList->addItem(QStringLiteral("Army Blue")); themeList->addItem(QStringLiteral("Retro")); themeList->addItem(QStringLiteral("Ebony")); themeList->addItem(QStringLiteral("Isabelle")); QGroupBox *colorGroupBox = new QGroupBox(QStringLiteral("Custom gradient")); QLinearGradient grBtoY(0, 0, 1, 100); grBtoY.setColorAt(1.0, Qt::black); grBtoY.setColorAt(0.67, Qt::blue); grBtoY.setColorAt(0.33, Qt::red); grBtoY.setColorAt(0.0, Qt::yellow); QPixmap pm(24, 100); QPainter pmp(&pm); pmp.setBrush(QBrush(grBtoY)); pmp.setPen(Qt::NoPen); pmp.drawRect(0, 0, 24, 100); QPushButton *gradientBtoYPB = new QPushButton(widget); gradientBtoYPB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); gradientBtoYPB->setIcon(QIcon(pm)); gradientBtoYPB->setIconSize(QSize(24, 100)); QLinearGradient grGtoR(0, 0, 1, 100); grGtoR.setColorAt(1.0, Qt::darkGreen); grGtoR.setColorAt(0.5, Qt::yellow); grGtoR.setColorAt(0.2, Qt::red); grGtoR.setColorAt(0.0, Qt::darkRed); pmp.setBrush(QBrush(grGtoR)); pmp.drawRect(0, 0, 24, 100); QPushButton *gradientGtoRPB = new QPushButton(widget); gradientGtoRPB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); gradientGtoRPB->setIcon(QIcon(pm)); gradientGtoRPB->setIconSize(QSize(24, 100)); QHBoxLayout *colorHBox = new QHBoxLayout; colorHBox->addWidget(gradientBtoYPB); colorHBox->addWidget(gradientGtoRPB); colorGroupBox->setLayout(colorHBox); vLayout->addWidget(modelGroupBox); vLayout->addWidget(selectionGroupBox); vLayout->addWidget(new QLabel(QStringLiteral("Camera Position"))); vLayout->addWidget(axisCameraSliderZ); vLayout->addWidget(axisCameraSliderY); vLayout->addWidget(new QLabel(QStringLiteral("Theme"))); vLayout->addWidget(themeList); vLayout->addWidget(colorGroupBox); widget->show(); modifier= new SurfaceGraph(graph, widget,parameters); if(!load){ QObject::connect(parent, SIGNAL(plotDataReceived(QList <QByteArray>)), modifier, SLOT(dataHandler(QList <QByteArray>))); QObject::connect(AFM_Scan_3D_RB, SIGNAL (toggled(bool)), this, SLOT(AFMButtonHandler(bool))); QObject::connect(this, SIGNAL (AFMStart()), modifier, SLOT (enableAFMModel())); QObject::connect(this, SIGNAL (AFMDone()), parent, SLOT (sendDone())); QObject::connect(this, SIGNAL (AFMStart()), parent, SLOT (sendGo())); QObject::connect(this, SIGNAL (AFMStart()), parent, SLOT(sendReady()));}
/* * This function is called straight from AbstractExecutor::execute, * which is called from executeExecutors, which is called from the * VoltDBEngine::executePlanFragments. So, this is really the start * of execution for this executor. * * The executor will already have been initialized by p_init. */ bool WindowFunctionExecutor::p_execute(const NValueArray& params) { VOLT_TRACE("windowFunctionExecutor::p_execute(start)\n"); // Input table Table * input_table = m_abstractNode->getInputTable(); assert(input_table); VOLT_TRACE("WindowFunctionExecutor: input table\n%s", input_table->debug().c_str()); m_inputSchema = input_table->schema(); assert(m_inputSchema); /* * Do this after setting the m_inputSchema. */ initWorkingTupleStorage(); TableWindow tableWindow(input_table); ProgressMonitorProxy pmp(m_engine->getExecutorContext(), this); m_pmp = &pmp; m_aggregateRow = new (m_memoryPool, m_aggTypes.size()) WindowAggregateRow(m_inputSchema, m_memoryPool); initAggInstances(); VOLT_TRACE("Beginning: %s", tableWindow.debug().c_str()); TableTuple nextTuple(m_inputSchema); /* * Force a call p_execute_finish when this is all over. */ EnsureCleanupOnExit finishCleanup(this); for (EdgeType etype = START_OF_INPUT, nextEtype = INVALID_EDGE_TYPE; etype != END_OF_INPUT; etype = nextEtype) { // Reset the aggregates if this is the // start of a partition group. The start of // input is a special form of this. if (etype == START_OF_INPUT || etype == START_OF_PARTITION_GROUP) { m_aggregateRow->resetAggs(); } // Find the next edge. This will // give the aggs a crack at each row // if they want it. nextEtype = findNextEdge(etype, tableWindow); // Let the aggs know the results // of the lookahead. lookaheadNextGroupForAggs(tableWindow); // Advance to the end of the current group. for (int idx = 0; idx < tableWindow.m_orderByGroupSize; idx += 1) { VOLT_TRACE("MiddleEdge: Window = %s", m_tableWindow->debug().c_str()); tableWindow.m_middleEdge.next(nextTuple); m_pmp->countdownProgress(); m_aggregateRow->recordPassThroughTuple(nextTuple); insertOutputTuple(); } endGroupForAggs(tableWindow, etype); VOLT_TRACE("FirstEdge: %s", m_tableWindow->debug().c_str()); } VOLT_TRACE("WindowFunctionExecutor: finalizing.."); cleanupInputTempTable(input_table); VOLT_TRACE("WindowFunctionExecutor::p_execute(end)\n"); return true; }
int main(int argc, char **argv) { //! [0] QApplication app(argc, argv); Q3DSurface *graph = new Q3DSurface(); QWidget *container = QWidget::createWindowContainer(graph); //! [0] if (!graph->hasContext()) { QMessageBox msgBox; msgBox.setText("Couldn't initialize the OpenGL context."); msgBox.exec(); return -1; } QSize screenSize = graph->screen()->size(); container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.6)); container->setMaximumSize(screenSize); container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); container->setFocusPolicy(Qt::StrongFocus); //! [1] QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); QVBoxLayout *vLayout = new QVBoxLayout(); hLayout->addWidget(container, 1); hLayout->addLayout(vLayout); vLayout->setAlignment(Qt::AlignTop); //! [1] widget->setWindowTitle(QStringLiteral("Surface example")); QGroupBox *modelGroupBox = new QGroupBox(QStringLiteral("Model")); QRadioButton *sqrtSinModelRB = new QRadioButton(widget); sqrtSinModelRB->setText(QStringLiteral("Sqrt && Sin")); sqrtSinModelRB->setChecked(false); QRadioButton *heightMapModelRB = new QRadioButton(widget); heightMapModelRB->setText(QStringLiteral("Height Map")); heightMapModelRB->setChecked(false); QVBoxLayout *modelVBox = new QVBoxLayout; modelVBox->addWidget(sqrtSinModelRB); modelVBox->addWidget(heightMapModelRB); modelGroupBox->setLayout(modelVBox); QGroupBox *selectionGroupBox = new QGroupBox(QStringLiteral("Selection Mode")); QRadioButton *modeNoneRB = new QRadioButton(widget); modeNoneRB->setText(QStringLiteral("No selection")); modeNoneRB->setChecked(false); QRadioButton *modeItemRB = new QRadioButton(widget); modeItemRB->setText(QStringLiteral("Item")); modeItemRB->setChecked(false); QRadioButton *modeSliceRowRB = new QRadioButton(widget); modeSliceRowRB->setText(QStringLiteral("Row Slice")); modeSliceRowRB->setChecked(false); QRadioButton *modeSliceColumnRB = new QRadioButton(widget); modeSliceColumnRB->setText(QStringLiteral("Column Slice")); modeSliceColumnRB->setChecked(false); QVBoxLayout *selectionVBox = new QVBoxLayout; selectionVBox->addWidget(modeNoneRB); selectionVBox->addWidget(modeItemRB); selectionVBox->addWidget(modeSliceRowRB); selectionVBox->addWidget(modeSliceColumnRB); selectionGroupBox->setLayout(selectionVBox); QSlider *axisMinSliderX = new QSlider(Qt::Horizontal, widget); axisMinSliderX->setMinimum(0); axisMinSliderX->setTickInterval(1); axisMinSliderX->setEnabled(true); QSlider *axisMaxSliderX = new QSlider(Qt::Horizontal, widget); axisMaxSliderX->setMinimum(1); axisMaxSliderX->setTickInterval(1); axisMaxSliderX->setEnabled(true); QSlider *axisMinSliderZ = new QSlider(Qt::Horizontal, widget); axisMinSliderZ->setMinimum(0); axisMinSliderZ->setTickInterval(1); axisMinSliderZ->setEnabled(true); QSlider *axisMaxSliderZ = new QSlider(Qt::Horizontal, widget); axisMaxSliderZ->setMinimum(1); axisMaxSliderZ->setTickInterval(1); axisMaxSliderZ->setEnabled(true); QComboBox *themeList = new QComboBox(widget); themeList->addItem(QStringLiteral("Qt")); themeList->addItem(QStringLiteral("Primary Colors")); themeList->addItem(QStringLiteral("Digia")); themeList->addItem(QStringLiteral("Stone Moss")); themeList->addItem(QStringLiteral("Army Blue")); themeList->addItem(QStringLiteral("Retro")); themeList->addItem(QStringLiteral("Ebony")); themeList->addItem(QStringLiteral("Isabelle")); QGroupBox *colorGroupBox = new QGroupBox(QStringLiteral("Custom gradient")); QLinearGradient grBtoY(0, 0, 1, 100); grBtoY.setColorAt(1.0, Qt::black); grBtoY.setColorAt(0.67, Qt::blue); grBtoY.setColorAt(0.33, Qt::red); grBtoY.setColorAt(0.0, Qt::yellow); QPixmap pm(24, 100); QPainter pmp(&pm); pmp.setBrush(QBrush(grBtoY)); pmp.setPen(Qt::NoPen); pmp.drawRect(0, 0, 24, 100); QPushButton *gradientBtoYPB = new QPushButton(widget); gradientBtoYPB->setIcon(QIcon(pm)); gradientBtoYPB->setIconSize(QSize(24, 100)); QLinearGradient grGtoR(0, 0, 1, 100); grGtoR.setColorAt(1.0, Qt::darkGreen); grGtoR.setColorAt(0.5, Qt::yellow); grGtoR.setColorAt(0.2, Qt::red); grGtoR.setColorAt(0.0, Qt::darkRed); pmp.setBrush(QBrush(grGtoR)); pmp.drawRect(0, 0, 24, 100); QPushButton *gradientGtoRPB = new QPushButton(widget); gradientGtoRPB->setIcon(QIcon(pm)); gradientGtoRPB->setIconSize(QSize(24, 100)); QHBoxLayout *colorHBox = new QHBoxLayout; colorHBox->addWidget(gradientBtoYPB); colorHBox->addWidget(gradientGtoRPB); colorGroupBox->setLayout(colorHBox); vLayout->addWidget(modelGroupBox); vLayout->addWidget(selectionGroupBox); vLayout->addWidget(new QLabel(QStringLiteral("Column range"))); vLayout->addWidget(axisMinSliderX); vLayout->addWidget(axisMaxSliderX); vLayout->addWidget(new QLabel(QStringLiteral("Row range"))); vLayout->addWidget(axisMinSliderZ); vLayout->addWidget(axisMaxSliderZ); vLayout->addWidget(new QLabel(QStringLiteral("Theme"))); vLayout->addWidget(themeList); vLayout->addWidget(colorGroupBox); widget->show(); SurfaceGraph *modifier = new SurfaceGraph(graph); QObject::connect(heightMapModelRB, &QRadioButton::toggled, modifier, &SurfaceGraph::enableHeightMapModel); QObject::connect(sqrtSinModelRB, &QRadioButton::toggled, modifier, &SurfaceGraph::enableSqrtSinModel); QObject::connect(modeNoneRB, &QRadioButton::toggled, modifier, &SurfaceGraph::toggleModeNone); QObject::connect(modeItemRB, &QRadioButton::toggled, modifier, &SurfaceGraph::toggleModeItem); QObject::connect(modeSliceRowRB, &QRadioButton::toggled, modifier, &SurfaceGraph::toggleModeSliceRow); QObject::connect(modeSliceColumnRB, &QRadioButton::toggled, modifier, &SurfaceGraph::toggleModeSliceColumn); QObject::connect(axisMinSliderX, &QSlider::valueChanged, modifier, &SurfaceGraph::adjustXMin); QObject::connect(axisMaxSliderX, &QSlider::valueChanged, modifier, &SurfaceGraph::adjustXMax); QObject::connect(axisMinSliderZ, &QSlider::valueChanged, modifier, &SurfaceGraph::adjustZMin); QObject::connect(axisMaxSliderZ, &QSlider::valueChanged, modifier, &SurfaceGraph::adjustZMax); QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), modifier, SLOT(changeTheme(int))); QObject::connect(gradientBtoYPB, &QPushButton::pressed, modifier, &SurfaceGraph::setBlackToYellowGradient); QObject::connect(gradientGtoRPB, &QPushButton::pressed, modifier, &SurfaceGraph::setGreenToRedGradient); modifier->setAxisMinSliderX(axisMinSliderX); modifier->setAxisMaxSliderX(axisMaxSliderX); modifier->setAxisMinSliderZ(axisMinSliderZ); modifier->setAxisMaxSliderZ(axisMaxSliderZ); sqrtSinModelRB->setChecked(true); modeItemRB->setChecked(true); themeList->setCurrentIndex(2); return app.exec(); }
static void run_tests_innerL() { TNoDefaults nd; auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("locatest"))); auto_ptr<CBaActiveScheduler> sched(new (ELeave) CBaActiveScheduler); CActiveScheduler::Install(sched.get()); c->SetDataDir(_L("c:\\system\\data\\context\\"), false); c->SetSettings(CBlackBoardSettings::NewL(*c, nd, KCLSettingsTuple)); auto_ptr<CBBDataFactory> f(CBBDataFactory::NewL()); c->SetBBDataFactory(f.get()); auto_ptr<CBBSession> sess(CBBSession::NewL(*c, f.get())); c->SetBBSession(sess.get()); c->SetActiveErrorReporter(output); auto_ptr<CPresenceMaintainer> pmp(CPresenceMaintainer::NewL(*c, 0, 0, 0, 0)); CPresenceMaintainerImpl* pm=(CPresenceMaintainerImpl*)pmp.get(); _LIT(cn, "cellname"); TBBLongString cellname(_L("cell1"), cn); CBBSensorEvent e(cn, KCellNameTuple, f.get()); e.iData.SetOwnsValue(EFalse); e.iData.SetValue(&cellname); e.iStamp=TTime(100); pm->NewSensorEventL(KCellNameTuple, KNullDesC, e); TInt isactive=0; if (pm->iNonsignificantTimer->IsActive()) isactive=1; TEST_EQUALS( 1, isactive, _L("nonsig1") ); { TBBBaseInfo b; b.iCurrent.iEntered=TTime(100); b.iCurrent.iLeft=TTime(0); b.iCurrent.iBaseName=_L("cell2"); e.iData.SetValue(&b); pm->NewSensorEventL(KBaseTuple, KNullDesC, e); if (pm->iNonsignificantTimer->IsActive()) isactive=1; else isactive=0; TEST_EQUALS( 0, isactive, _L("nonsig2") ); } cellname()=_L("cell3"); e.iStamp=TTime(100); e.iData.SetValue(&cellname); pm->NewSensorEventL(KCellNameTuple, KNullDesC, e); if (pm->iNonsignificantTimer->IsActive()) isactive=1; else isactive=0; TEST_EQUALS( 0, isactive, _L("nonsig3") ); cellname()=_L("cell4"); e.iStamp=TTime(110); e.iData.SetValue(&cellname); pm->NewSensorEventL(KCellNameTuple, KNullDesC, e); if (pm->iNonsignificantTimer->IsActive()) isactive=1; else isactive=0; TEST_EQUALS( 0, isactive, _L("nonsig4") ); { TBBBaseInfo b; b.iCurrent.iEntered=TTime(100); b.iCurrent.iLeft=TTime(110); b.iCurrent.iBaseName=_L("cell2"); e.iData.SetValue(&b); pm->NewSensorEventL(KBaseTuple, KNullDesC, e); if (pm->iNonsignificantTimer->IsActive()) isactive=1; else isactive=0; TEST_EQUALS( 0, isactive, _L("nonsig5") ); } cellname()=_L("cell3"); e.iStamp=TTime(120); e.iData.SetValue(&cellname); pm->NewSensorEventL(KCellNameTuple, KNullDesC, e); if (pm->iNonsignificantTimer->IsActive()) isactive=1; else isactive=1; TEST_EQUALS( 1, isactive, _L("nonsig6") ); }
int main( int argc, const char* argv[]) { g_errorhnd = strus::createErrorBuffer_standard( stderr, 1, NULL/*debug trace interface*/); if (!g_errorhnd) return -1; if (argc <= 1 || std::strcmp( argv[1], "-h") == 0 || std::strcmp( argv[1], "--help") == 0) { printUsage( argc, argv); return 0; } else if (argc < 3) { std::cerr << "ERROR too few parameters" << std::endl; printUsage( argc, argv); return 1; } else if (argc > 4) { std::cerr << "ERROR too many parameters" << std::endl; printUsage( argc, argv); return 1; } try { // Create random test collection: int nofDocs = (int)g_random.get( 0, 1000000) - 500000; int nofDocsPart = nofDocs / 2; unsigned int nofTerms = getUintValue( argv[1]); unsigned int diffRange = getUintValue( argv[2]); std::string storagePath = (argc > 3) ? argv[3] : ""; TermCollection collection( nofTerms, diffRange); // Build statistics: strus::local_ptr<strus::StatisticsProcessorInterface> pmp( strus::createStandardStatisticsProcessor( strus::StatisticsDefaultNofBlocks, strus::StatisticsDefaultMsgChunkSize, g_errorhnd)); strus::local_ptr<strus::StatisticsBuilderInterface> builder( pmp->createBuilder( storagePath)); if (!builder.get()) { throw std::runtime_error( g_errorhnd->fetchError()); } builder->setNofDocumentsInsertedChange( nofDocsPart); typedef TermCollection::Term Term; unsigned int termsByteSize = 0; std::vector<Term>::const_iterator ti = collection.termar.begin(), te = collection.termar.end(); int rr = collection.termar.size() / 3 + 1; for (int tidx=0; ti != te; ++ti,++tidx) { #ifdef STRUS_LOWLEVEL_DEBUG std::cerr << "add df change '" << ti->type << "' '" << ti->value << "' " << ti->diff << std::endl; #endif termsByteSize += ti->type.size() + ti->value.size() + 5; builder->addDfChange( ti->type.c_str(), ti->value.c_str(), ti->diff); if ((int)g_random.get( 0, rr) == 1) { int nn = (nofDocs - nofDocsPart) / 2; builder->setNofDocumentsInsertedChange( nn); nofDocsPart += nn; } } builder->setNofDocumentsInsertedChange( nofDocs - nofDocsPart); // Iterate through messages and accumulate statistics stored: std::size_t blobsize = 0; int nofDocsInserted = 0; std::set<Term> termset; strus::local_ptr<strus::StatisticsIteratorInterface> iterator; if (storagePath.empty()) { iterator.reset( builder->createIteratorAndRollback()); } else { strus::TimeStamp timeStampBeforeNow( ::time(NULL)-1); if (!builder->commit()) { throw std::runtime_error( g_errorhnd->fetchError()); } iterator.reset( builder->createIterator( timeStampBeforeNow)); if (!iterator.get()) { throw std::runtime_error( g_errorhnd->fetchError()); } strus::TimeStamp timeStamp10MinutesBeforeNow( ::time(NULL)-600); builder->releaseStatistics( timeStamp10MinutesBeforeNow); } strus::StatisticsMessage msg = iterator->getNext(); for (; !msg.empty(); msg = iterator->getNext()) { strus::local_ptr<strus::StatisticsViewerInterface> viewer( pmp->createViewer( msg.ptr(), msg.size())); if (!viewer.get()) { throw std::runtime_error( g_errorhnd->fetchError()); } nofDocsInserted += viewer->nofDocumentsInsertedChange(); blobsize += msg.size(); #ifdef STRUS_LOWLEVEL_DEBUG int blockcnt = 0; std::cerr << "fetch message " << ++blockcnt << " " << msg.size() << std::endl; #endif strus::TermStatisticsChange rec; while (viewer->nextDfChange( rec)) { #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "result df change " << rec.type() << " " << rec.value() << " " << rec.increment() << std::endl; #endif termset.insert( Term( rec.type(), rec.value(), rec.increment())); } } if (g_errorhnd->hasError()) { throw std::runtime_error( g_errorhnd->fetchError()); } // Compare test output with expected: std::vector<Term> termar; std::set<Term>::const_iterator si = termset.begin(), se = termset.end(); for (; si != se; ++si) { termar.push_back( *si); } if (nofDocs != nofDocsInserted) { throw std::runtime_error( strus::string_format( "statistics number of documents %d does not match expected %d", nofDocsInserted, nofDocs)); } if (collection.termar.size() != termar.size()) { std::cerr << "COLLECTION SIZE " << collection.termar.size() << " MESSAGE ITEMS " << termar.size() << std::endl; throw std::runtime_error( "statistics message number of messages does not match"); } std::vector<Term>::const_iterator oi = collection.termar.begin(), oe = collection.termar.end(); ti = termar.begin(), te = termar.end(); for (int tidx=0; oi != oe && ti != te; ++oi,++ti) { if (oi->type != ti->type) { std::cerr << "[" << tidx << "] TYPE '" << ti->type << "' != '" << oi->type << "'" << std::endl; throw std::runtime_error( "statistics message item type does not match"); } if (oi->value != ti->value) { std::cerr << "[" << tidx << "] VALUE '" << ti->value << "' != '" << oi->value << "'" << std::endl; throw std::runtime_error( "statistics message item value does not match"); } if (oi->diff != ti->diff) { std::cerr << "[" << tidx << "] DIFF '" << ti->diff << "' != '" << oi->diff << "'" << std::endl; throw std::runtime_error( "statistics message item diff does not match"); } } if (g_errorhnd->hasError()) { throw std::runtime_error( g_errorhnd->fetchError()); } std::cerr << "processed blob of " << blobsize << " [uncompressed " << termsByteSize << "] bytes" << std::endl; std::cerr << "Ok [" << collection.termar.size() << "]" << std::endl; return 0; } catch (const std::runtime_error& e) { std::cerr << "ERROR " << e.what() << std::endl; } catch (const std::exception& e) { std::cerr << "EXCEPTION " << e.what() << std::endl; } return 4; }