示例#1
0
void ScaleEngine::autoScale (int maxNumSteps, double &x1, double &x2, double &stepSize) const
{
	if (!hasBreak() || testAttribute(QwtScaleEngine::Inverted)){
		QwtScaleEngine *engine;
		if (d_type == QwtScaleTransformation::Log10)
			engine = new QwtLog10ScaleEngine();
		else
			engine = new QwtLinearScaleEngine();
		
		engine->setAttributes(attributes());
    	engine->setReference(reference());
    	engine->setMargins(loMargin(), hiMargin());
		engine->autoScale(maxNumSteps, x1, x2, stepSize);
		delete engine;
	} else {
		QwtScaleEngine *engine;
		if (d_type == QwtScaleTransformation::Log10)
			engine = new QwtLog10ScaleEngine();
		else
			engine = new QwtLinearScaleEngine();
		
		engine->setAttributes(attributes());
		double breakLeft = d_break_left;
		engine->autoScale(maxNumSteps, x1, breakLeft, stepSize);
		delete engine;
		
		engine = new QwtLinearScaleEngine();
		engine->setAttributes(attributes());
		double breakRight = d_break_right;
		engine->autoScale(maxNumSteps, breakRight, x2, stepSize);
		delete engine;
	}
}
示例#2
0
void ScaleEngine::autoScale (int maxNumSteps, double &x1, double &x2, double &stepSize) const
{
	if (!hasBreak() || testAttribute(QwtScaleEngine::Inverted)){
		QwtScaleEngine *engine = newScaleEngine();
		engine->setAttributes(attributes());
		engine->setReference(reference());
		engine->setMargins(lowerMargin(), upperMargin());

		if (type() == ScaleTransformation::Log10 || type() == ScaleTransformation::Ln || type() == ScaleTransformation::Log2){
			if (x1 <= 0.0)
				x1 = LOG_MIN;
			if (x2 <= 0.0)
				x2 = LOG_MIN;
		}

		engine->autoScale(maxNumSteps, x1, x2, stepSize);
		delete engine;
	} else {
		QwtScaleEngine *engine = newScaleEngine();
		engine->setAttributes(attributes());
		double breakLeft = d_break_left;
		engine->autoScale(maxNumSteps, x1, breakLeft, stepSize);
		delete engine;

		engine = new QwtLinearScaleEngine();
		engine->setAttributes(attributes());
		double breakRight = d_break_right;
		engine->autoScale(maxNumSteps, breakRight, x2, stepSize);
		delete engine;
	}
}
示例#3
0
QwtScaleDiv ScaleEngine::divideScale(double x1, double x2, int maxMajSteps,
		int maxMinSteps, double stepSize) const
{
	QwtScaleEngine *engine;
	if (!hasBreak()){
        engine = newScaleEngine();
		QwtScaleDiv div = engine->divideScale(x1, x2, maxMajSteps, maxMinSteps, stepSize);
		delete engine;
		return div;
	}

    double lb = d_break_left;
    double rb = d_break_right;
	double step1 = d_step_before;
	double step2 = d_step_after;
    if (x1 > x2){
        lb = d_break_right;
        rb = d_break_left;
		step1 = d_step_after;
		step2 = d_step_before;
        if (d_log10_scale_after)
            engine = new QwtLog10ScaleEngine();
        else
            engine = new QwtLinearScaleEngine();
    } else
		engine = newScaleEngine();

    int max_min_intervals = d_minor_ticks_before;
	if (d_minor_ticks_before == 1)
		max_min_intervals = 3;
	if (d_minor_ticks_before > 1)
		max_min_intervals = d_minor_ticks_before + 1;

	QwtScaleDiv div1 = engine->divideScale(x1, lb, maxMajSteps/2, max_min_intervals, step1);

    max_min_intervals = d_minor_ticks_after;
	if (d_minor_ticks_after == 1)
		max_min_intervals = 3;
	if (d_minor_ticks_after > 1)
		max_min_intervals = d_minor_ticks_after + 1;

    delete engine;
    if (testAttribute(QwtScaleEngine::Inverted))
		engine = newScaleEngine();
    else if (d_log10_scale_after)
		engine = new QwtLog10ScaleEngine();
	else
		engine = new QwtLinearScaleEngine();

    QwtScaleDiv div2 = engine->divideScale(rb, x2, maxMajSteps/2, max_min_intervals, step2);

    QwtValueList ticks[QwtScaleDiv::NTickTypes];
    ticks[QwtScaleDiv::MinorTick] = div1.ticks(QwtScaleDiv::MinorTick) + div2.ticks(QwtScaleDiv::MinorTick);
    ticks[QwtScaleDiv::MediumTick] = div1.ticks(QwtScaleDiv::MediumTick) + div2.ticks(QwtScaleDiv::MediumTick);
    ticks[QwtScaleDiv::MajorTick] = div1.ticks(QwtScaleDiv::MajorTick) + div2.ticks(QwtScaleDiv::MajorTick);

	delete engine;
	return QwtScaleDiv(x1, x2, ticks);
}
示例#4
0
EigenPlotDlg::EigenPlotDlg(QWidget* parent) :
   QDialog(parent),
   mpPlot(NULL),
   mpCurve(NULL),
   mpComponentsSpin(NULL)
{
   // Eigen plot
   mpPlot = new QwtPlot(this);
   mpPlot->installEventFilter(this);
   mpPlot->setAutoFillBackground(true);

   QFont ftAxis = QApplication::font();
   ftAxis.setBold(true);
   ftAxis.setPointSize(10);

   QwtText bottomText("Number of Components");
   bottomText.setFont(ftAxis);
   mpPlot->setAxisTitle(QwtPlot::xBottom, bottomText);

   QwtText leftText("Eigen Values");
   leftText.setFont(ftAxis);
   mpPlot->setAxisTitle(QwtPlot::yLeft, leftText);

   QwtScaleEngine* pLinearScale = mpPlot->axisScaleEngine(QwtPlot::xBottom);
   pLinearScale->setAttribute(QwtScaleEngine::Floating);

   QwtLog10ScaleEngine* pLogScale = new QwtLog10ScaleEngine();
   pLogScale->setAttribute(QwtScaleEngine::Floating);
   mpPlot->setAxisScaleEngine(QwtPlot::yLeft, pLogScale);

   QPalette plotPalette = mpPlot->palette();
   plotPalette.setColor(QPalette::Window, Qt::white);
   mpPlot->setPalette(plotPalette);

   QwtPlotCanvas* pPlotCanvas = mpPlot->canvas();
   pPlotCanvas->setFrameStyle(QFrame::NoFrame);

   QwtPlotLayout* pPlotLayout = mpPlot->plotLayout();
   pPlotLayout->setMargin(5);

   QwtPlotGrid* pPlotGrid = new QwtPlotGrid();
   pPlotGrid->setPen(QPen(Qt::DotLine));
   pPlotGrid->attach(mpPlot);
   mpPlot->replot();

   // Number of components
   QLabel* pComponentsLabel = new QLabel("Number of Components:", this);
   mpComponentsSpin = new QSpinBox(this);
   mpComponentsSpin->setFixedWidth(50);
   mpComponentsSpin->setMinimum(1);

   QLabel* pDescriptionLabel = new QLabel("To set, left click in the plot or enter a value.", this);
   pDescriptionLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
   pDescriptionLabel->setWordWrap(true);

   QFont descriptionFont(pDescriptionLabel->font());
   descriptionFont.setItalic(true);
   pDescriptionLabel->setFont(descriptionFont);

   QHBoxLayout* pComponentsLayout = new QHBoxLayout();
   pComponentsLayout->setMargin(0);
   pComponentsLayout->setSpacing(5);
   pComponentsLayout->addWidget(pComponentsLabel);
   pComponentsLayout->addWidget(mpComponentsSpin);
   pComponentsLayout->addWidget(pDescriptionLabel, 10);

   // Horizontal line
   QFrame* pLine = new QFrame(this);
   pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);

   // Buttons
   QPushButton* pOk = new QPushButton("&OK", this);
   QPushButton* pCancel = new QPushButton("&Cancel", this);
   connect(pOk, SIGNAL(clicked()), this, SLOT(accept()));
   connect(pCancel, SIGNAL(clicked()), this, SLOT(reject()));

   QHBoxLayout* pButtonLayout = new QHBoxLayout();
   pButtonLayout->setMargin(0);
   pButtonLayout->setSpacing(5);
   pButtonLayout->addStretch(10);
   pButtonLayout->addWidget(pOk);
   pButtonLayout->addWidget(pCancel);

   // Layout
   QGridLayout* pGrid = new QGridLayout(this);
   pGrid->setMargin(10);
   pGrid->setSpacing(10);
   pGrid->addWidget(mpPlot, 0, 0);
   pGrid->addLayout(pComponentsLayout, 1, 0);
   pGrid->addWidget(pLine, 2, 0);
   pGrid->addLayout(pButtonLayout, 3, 0);
   pGrid->setRowStretch(0, 10);

   // Initialization
   setWindowTitle("PCA Components");
   setModal(true);
   resize(440, 300);
}