QCustomPlot Discussion and Comments

hi,
first of all I would like to thank for this amazing feature that recently is added in version 1.2, you did a nice job.
I have an advice about QCPColorMap. I think it is better to add an option for limiting zoom and drag, for example can not drag plot out of the range that Specified and can not zoom out of the QCPColorMap's ranges. because when someone use colorMap, he/she want to drag and zoom on area that colorMap paint so zooming and dragging without limitation is useless and can be annoying in some cases. I think you should have added an option that zooming and dragging can be act just in the ranges that is set for QCPColorMap. I hope understand my intention.
best regards,
alireza aramoun

This can be easily realized in user-code. Just connect slots to the rangeChanged signals of your axes and restrict the ranges to the respective values (by calling setRange again, with new bounded lower and upper values).

I have already done what you are saying for zooming but I had problem with dragging. this is what I've done in its axes slots:

void MainWindow::slt_plotRangeChangedY(const QCPRange &newRange)
{
    if(newRange.lower < 0)
    {
        ui->widget->yAxis->setRange(0, ui->widget->yAxis->range().upper);
    }
    if(newRange.upper > 800)
    {
         ui->widget->yAxis->setRange(ui->widget->yAxis->range().lower, 800);
    }
}

in this code when user want to drag the plot around lower bound or upper bound, the content of graph will be streched

Yes, that's because you don't enforce a size. In your lower < 0 condition, you should also set the upper range to the current range size, so something like this:

QCPRange boundedRange = newRange;
double lowerRangeBound = 0;
double upperRangeBound = 800;
if (boundedRange.size() > upperRangeBound-lowerRangeBound)
{
  boundedRange = QCPRange(lowerRangeBound, upperRangeBound)
} else
{
  if(boundedRange.lower < lowerRangeBound)
  {
    boundedRange.lower = lowerRangeBound;
    boundedRange.upper = lowerRangeBound+boundedRange.size();
  }
  if(boundedRange.upper > upperRangeBound)
  {
    boundedRange.lower = upperRangeBound-boundedRange.size();
    boundedRange.upper = upperRangeBound;
  }
}
ui->widget->yAxis->setRange(boundedRange);

Note that I've added an additional check for the total size to be within the allowed bounds, to prevent recursion.

thank for your code, I've tested this code and it works perfectly for upper bounds but problem persist at the lower bounds and when drag in lower bounds the content of graph will be stretched. I think we should do something that does n't update the upper bound in condition

if(boundedRange.lower < lowerRangeBound)
for example when enter for the first time in this condition, save the upper bound value in a variable and control entering and leaving state with a flag but I think it can be done in better and optimum way, please help me to find this way.
thanks in advance,
Alireza

Ah yes, the code was brain-to-forum so I forgot one thing: When we change the lower/upper of the boundedRange, of course its size changes. This is no problem for the boundedRange.upper > upperRangeBound case, because here the size is used before boundedRange changes. But in the boundedRange.lower < lowerRangeBound, you see that the boundedRange.size() is used in the second line, after boundedRange.lower has changed already, which makes the size wrong. Here's the correct code:

  QCPRange boundedRange = newRange;
  double lowerRangeBound = 0;
  double upperRangeBound = 800;
  if (boundedRange.size() > upperRangeBound-lowerRangeBound)
  {
    boundedRange = QCPRange(lowerRangeBound, upperRangeBound);
  } else
  {
    double oldSize = boundedRange.size();
    if (boundedRange.lower < lowerRangeBound)
    {
      boundedRange.lower = lowerRangeBound;
      boundedRange.upper = lowerRangeBound+oldSize;
    }
    if (boundedRange.upper > upperRangeBound)
    {
      boundedRange.lower = upperRangeBound-oldSize;
      boundedRange.upper = upperRangeBound;
    }
  }
  ui->widget->yAxis->setRange(boundedRange);

as always thanks for your excellent support