void MainWindow::colorMapMouseMove(QMouseEvent *event) { if (QCPColorMap *map = qobject_cast<QCPColorMap*>(mCustomPlot->plottable(0))) { double keyCoord = map->keyAxis()->pixelToCoord(map->keyAxis()->orientation()==Qt::Horizontal ? event->pos().x() : event->pos().y()); double valueCoord = map->valueAxis()->pixelToCoord(map->valueAxis()->orientation()==Qt::Horizontal ? event->pos().x() : event->pos().y()); int ik, iv; map->data()->coordToCell(keyCoord, valueCoord, &ik, &iv); map->data()->fill(0); map->data()->setCell(ik, iv, 1); map->rescaleDataRange(true); double ck, cv; map->data()->cellToCoord(ik, iv, &ck, &cv); if (mCustomPlot->itemCount() == 0) { QCPItemTracer *t = new QCPItemTracer(mCustomPlot); mCustomPlot->addItem(t); t->position->setType(QCPItemPosition::ptPlotCoords); t->position->setCoords(ck, cv); t->position->setAxes(map->keyAxis(), map->valueAxis()); t->setClipToAxisRect(false); t->setStyle(QCPItemTracer::tsCircle); t->setPen(QPen(Qt::red)); } else if (QCPItemTracer *t = qobject_cast<QCPItemTracer*>(mCustomPlot->item(0))) t->position->setCoords(ck, cv); mCustomPlot->replot(); } }
//----------------------------------------------------------------------------------------------- // Plots the case //----------------------------------------------------------------------------------------------- void Plot::addToPlot(Case *c, bool replot) { m_plotted_cases.push_back(c); // finding what to plot double value; double max_real_var = c->numberOfRealVariables(); double max_int_var = max_real_var + c->numberOfIntegerVariables(); double max_bin_var = max_int_var + c->numberOfBinaryVariables(); int index = p_series->itemData(p_series->currentIndex()).toInt(); if(index == 0) value = c->objectiveValue(); // objective else if(index <= max_real_var) // real variable { value = c->realVariableValue(index-1); } else if(index <= max_int_var) // int variable { value = c->integerVariableValue(index - max_real_var -1); } else if(index <= max_bin_var) // bin variable { value = c->binaryVariableValue(index - max_int_var -1); } else // constraint { value = c->constraintValue(index - max_bin_var -1); } // adding to plot m_custom_plot.graph(0)->addData(m_plotted_cases.size(), value); // adding point to graph 1 if infeasible if(!p_mainwindow->runner()->isFeasible(c)) m_custom_plot.graph(1)->addData(m_plotted_cases.size(), value); // x axis range if(m_cases.size() >= 5) m_custom_plot.xAxis->setRange(m_plotted_cases.size() - p_sld_xaxis->value(), m_plotted_cases.size() + 1); // y axis range if(m_plotted_cases.size() == 1) { m_min = value*0.9; m_max = value*1.1; } else { if(value < m_min) m_min = value; if(value > m_max) m_max = value; } double padding = (m_max - m_min)*0.1; m_custom_plot.yAxis->setRange(m_min - padding, m_max + padding); // adding tracer QCPItemTracer *tracer = new QCPItemTracer(&m_custom_plot); tracer->setGraph(m_custom_plot.graph(0)); tracer->setGraphKey(m_plotted_cases.size()); tracer->setStyle(QCPItemTracer::tsPlus); tracer->setSize(20); QPen pen(Qt::blue); pen.setWidth(0); pen.setStyle(Qt::NoPen); tracer->setPen(pen); QPen pen_sel(Qt::green); pen_sel.setWidth(1); tracer->setSelectedPen(pen_sel); tracer->setSelectable(true); m_custom_plot.addItem(tracer); // updating the slider max p_sld_xaxis->setMaximum(m_plotted_cases.size()); if(!m_user_changed_slider) p_sld_xaxis->setValue(m_plotted_cases.size()); else { if(m_plotted_cases.size() > 5) m_custom_plot.xAxis->setRange(m_plotted_cases.size() - p_sld_xaxis->value(), m_plotted_cases.size() + 1); // checking if the x-axis tick step must change if(p_sld_xaxis->value() > 10) { int tick = p_sld_xaxis->value() / 10; m_custom_plot.xAxis->setTickStep(tick); } if(replot) m_custom_plot.replot(); } // m_custom_plot.replot(); }