QCustomPlot Discussion and Comments

fix WET code defect in QCPAxisRect::graphs()Return to overview

This is the solution, proposed change to the existing codebase.

Instead of having 3 times "mParentPlot->mGraphs.at(i);" it's better to introduce a var, for example 'g':

QList<QCPGraph*> QCPAxisRect::graphs() const
{
  // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries
  QList<QCPGraph*> result;
  for (int i=0; i<mParentPlot->mGraphs.size(); ++i)
  {
    QCPGraph *g = mParentPlot->mGraphs.at(i);
    if (g->keyAxis()->axisRect() == this || g->valueAxis()->axisRect() == this)
      result.append(g);
  }
  return result;
}

WET means "We enjoy typing", in the opposite of DRY principle (Do not repeat yourself).

Also, mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() causes a segfault if mKeyAxis QPointer is null.