Beispiel #1
0
FlexHelper::FlexHelper(QWidget* parent) : QObject(parent), impl(new FlexHelperImplWin)
{
    impl->_buttons = new FlexButtons(parent, parent);
    impl->_extents = new FlexExtents(parent, parent);
    connect(impl->_extents->_dockPullButton, SIGNAL(clicked()), SLOT(on_button_clicked()));
    connect(impl->_extents->_autoHideButton, SIGNAL(clicked()), SLOT(on_button_clicked()));
    connect(impl->_buttons->_clsButton, SIGNAL(clicked()), SLOT(on_button_clicked()));
    connect(impl->_buttons->_maxButton, SIGNAL(clicked()), SLOT(on_button_clicked()));
    connect(impl->_buttons->_minButton, SIGNAL(clicked()), SLOT(on_button_clicked()));
    parent->installEventFilter(this);
}
ribi::QtToolTestApproximatorXyzMainDialog::QtToolTestApproximatorXyzMainDialog(QWidget *parent) noexcept :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtToolTestApproximatorXyzMainDialog),
  m_approximator(),
  m_data(CreateData())
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //Set up the plots and curves
  GetPlot(0)->setTitle("Approximator, for z = 0.0");
  GetPlot(1)->setTitle("Approximator, for z = 0.5");
  GetPlot(2)->setTitle("Approximator, for z = 1.0");
  for (auto i=0; i!=m_n_curves; ++i)
  {
    const auto plot = GetPlot(i);
    plot->setAxisTitle(QwtPlot::xBottom,"X");
    plot->setAxisTitle(QwtPlot::yLeft,"Y");
    #ifdef _WIN32
    plot->setCanvasBackground(QBrush(QColor(255,255,255)));
    #else
    plot->setCanvasBackground(QColor(255,255,255));
    #endif

    const auto curve_values = GetCurveValues(i);
    assert(curve_values);
    curve_values->setTitle("Points");
    curve_values->attach(plot.get());
    curve_values->setStyle(QwtPlotCurve::Dots);
    curve_values->setPen(QPen(QColor(255,0,0),5));

    const auto curve_approximation = GetCurveApproximation(i);
    assert(curve_approximation);
    curve_approximation->setTitle("Approximation");
    curve_approximation->attach(plot.get());
    curve_approximation->setStyle(QwtPlotCurve::Dots);
    curve_approximation->setPen(QPen(QColor(0,0,255),3));

    //Add grid
    {
      QwtPlotGrid * const grid = new QwtPlotGrid;
      grid->setPen(QPen(QColor(128,128,128)));
      grid->attach(plot.get());
    }
    //Add zoomer
    {
      new QwtPlotZoomer(plot->canvas());
    }
    //Add legend
    {
      QwtLegend * const legend = new QwtLegend;
      legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
      plot->insertLegend(legend, QwtPlot::RightLegend);
    }

    plot->setAxisScale(
      QwtPlot::xBottom,
      static_cast<double>(ui->box_int_x->minimum()),
      static_cast<double>(ui->box_int_x->maximum())
    );
    plot->setAxisScale(
      QwtPlot::yLeft,
      static_cast<double>(ui->box_double_y->minimum()),
      static_cast<double>(ui->box_double_y->maximum())
    );

    //Add to dialog
    assert(ui->verticalLayout->layout());
    ui->verticalLayout->layout()->addWidget(plot.get());
  }




  //Add some nice testing values
  ui->box_int_x->setValue(ui->box_int_x->minimum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->minimum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(0);
  ui->box_double_y->setValue(0.0);
}
ribi::QtToolTestMultiApproximatorMainDialog::QtToolTestMultiApproximatorMainDialog(QWidget *parent) noexcept :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtToolTestMultiApproximatorMainDialog),
  m_multi_approximator(),
  m_curve_approximation(new QwtPlotCurve),
  m_curve_multi_approximation(new QwtPlotCurve),
  m_curve_multi_values(new QwtPlotCurve),
  m_curve_values(new QwtPlotCurve),
  m_multi_plot(new QwtPlot),
  m_plot(new QwtPlot)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //Set up the plots
  assert(m_multi_plot);
  m_multi_plot->setTitle("MultiApproximator");
  m_multi_plot->setAxisTitle(QwtPlot::xBottom,"Key");
  m_multi_plot->setAxisTitle(QwtPlot::yLeft,"Value");
  #ifdef _WIN32
  m_multi_plot->setCanvasBackground(QBrush(QColor(255,255,255)));
  #else
  m_multi_plot->setCanvasBackground(QColor(255,255,255));
  #endif

  assert(m_plot);
  m_plot->setTitle("Approximator");
  m_plot->setAxisTitle(QwtPlot::xBottom,"Key");
  m_plot->setAxisTitle(QwtPlot::yLeft,"Value");
  #ifdef _WIN32
  m_plot->setCanvasBackground(QBrush(QColor(255,255,255)));
  #else
  m_plot->setCanvasBackground(QColor(255,255,255));
  #endif

  //Create plots
  assert(m_curve_multi_values);
  m_curve_multi_values->setTitle("Points");
  m_curve_multi_values->attach(m_multi_plot.get());
  m_curve_multi_values->setStyle(QwtPlotCurve::Dots);
  m_curve_multi_values->setPen(QPen(QColor(255,0,0),5));

  assert(m_curve_multi_approximation);
  m_curve_multi_approximation->setTitle("Approximation");
  m_curve_multi_approximation->attach(m_multi_plot.get());
  m_curve_multi_approximation->setStyle(QwtPlotCurve::Lines);
  m_curve_multi_approximation->setPen(QPen(QColor(0,0,255),3));

  assert(m_curve_values);
  m_curve_values->setTitle("Points");
  m_curve_values->attach(m_plot.get());
  m_curve_values->setStyle(QwtPlotCurve::Dots);
  m_curve_values->setPen(QPen(QColor(255,0,0),5));

  assert(m_curve_approximation);
  m_curve_approximation->setTitle("Approximation");
  m_curve_approximation->attach(m_plot.get());
  m_curve_approximation->setStyle(QwtPlotCurve::Lines);
  m_curve_approximation->setPen(QPen(QColor(0,0,255),3));

  //Add grids
  {
    QwtPlotGrid * const grid = new QwtPlotGrid;
    grid->setPen(QPen(QColor(128,128,128)));
    grid->attach(m_multi_plot.get());
  }
  {
    QwtPlotGrid * const grid = new QwtPlotGrid;
    grid->setPen(QPen(QColor(128,128,128)));
    grid->attach(m_plot.get());
  }
  //Add zoomers
  //{
  //  new QwtPlotZoomer(m_multi_plot->canvas());
  //  new QwtPlotZoomer(m_plot->canvas());
  //}
  //Add legends
  {
    QwtLegend * const legend = new QwtLegend;
    legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
    m_multi_plot->insertLegend(legend, QwtPlot::RightLegend);
  }
  {
    QwtLegend * const legend = new QwtLegend;
    legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
    m_plot->insertLegend(legend, QwtPlot::RightLegend);
  }

  assert(ui->verticalLayout->layout());
  ui->verticalLayout->layout()->addWidget(m_multi_plot.get());
  ui->verticalLayout->layout()->addWidget(m_plot.get());

  m_multi_plot->setAxisScale(
    QwtPlot::xBottom,
    static_cast<double>(ui->box_int_x->minimum()),
    static_cast<double>(ui->box_int_x->maximum())
  );
  m_multi_plot->setAxisScale(
    QwtPlot::yLeft,
    static_cast<double>(ui->box_double_y->minimum()),
    static_cast<double>(ui->box_double_y->maximum())
  );

  m_plot->setAxisScale(
    QwtPlot::xBottom,
    static_cast<double>(ui->box_int_x->minimum()),
    static_cast<double>(ui->box_int_x->maximum())
  );
  m_plot->setAxisScale(
    QwtPlot::yLeft,
    static_cast<double>(ui->box_double_y->minimum()),
    static_cast<double>(ui->box_double_y->maximum())
  );

  //Add some nice testing values
  const double min_x = ui->box_int_x->minimum();
  const double max_x = ui->box_int_x->maximum();
  const double min_y = ui->box_double_y->minimum();
  const double max_y = ui->box_double_y->maximum();
  const double dy = max_y / 4.0;

  ui->box_int_x->setValue(min_x / 2);
  ui->box_double_y->setValue((max_y / 2.0) + dy);
  on_button_clicked();
  ui->box_double_y->setValue((max_y / 2.0) - dy);
  on_button_clicked();

  ui->box_int_x->setValue(min_x / 4);
  ui->box_double_y->setValue((min_y / 2.0) + dy);
  on_button_clicked();
  ui->box_double_y->setValue((min_y / 2.0) - dy);
  on_button_clicked();

  ui->box_int_x->setValue(max_x / 4);
  ui->box_double_y->setValue((max_y / 2.0) + dy);
  on_button_clicked();
  ui->box_double_y->setValue((max_y / 2.0) - dy);
  on_button_clicked();

  ui->box_int_x->setValue(max_x / 2);
  ui->box_double_y->setValue((min_y / 2.0) + dy);
  on_button_clicked();
  ui->box_double_y->setValue((min_y / 2.0) - dy);
  on_button_clicked();

  ui->box_int_x->setValue(0);
  ui->box_double_y->setValue(0.0);
}