Key-based grid lookups

Grids shows reading a grid cell by row index: getString(prop, elt, line) and friends. That index has to come from somewhere — usually a loop, or mCurrentLine tracked by whatever is currently executing that row. Sometimes neither applies: the row you want is identified by the value of one of its own columns, not by its position.

findGridRow(): turn a key value into a row index

Sequencer keeps a focusprofiles grid mapping a filter slot to the focus profile to request for it. Given the current filter index, it needs the matching row — not the n-th one:

// src/modules/sequencer/sequencer.cpp, findGridRow() comment
int findGridRow(const QString &propName, const QString &keyCol, const QString &keyValue);

It reads the key column through whichever getter matches its actual declared element type (int/float/string), not blindly as a string — the comment on its own implementation explains why that matters:

// libs/basemodule.cpp
int Basemodule::findGridRow(const QString &propName, const QString &keyCol, const QString &keyValue)
{
    // Read the key column through the getter matching its real declared
    // type, not blindly as a string: getString(prop, elt, line) hard
    // static_cast<ValueString*>'s the grid cell, undefined behavior for
    // any other type (found while making sequencer's "filter" an int key
    // column, issue #240 - this generic helper is shared by every module,
    // so any future int/float-keyed grid would have hit the same crash).
    ...
}

That issue is exactly why a key-typed lookup belongs in Basemodule itself rather than being reimplemented per module: a naive “loop and compare as string” version is one int-keyed grid away from undefined behavior.

The keyCol/keyValue overloads: skip the index entirely

Finding the row is usually only a means to read one cell from it — getGridString()/getGridFloat()/getGridInt() each have a second overload that does both steps at once:

QString getGridString(const QString &propName, const QString &colName, const QString &keyCol, const QString &keyValue);
double  getGridFloat (const QString &propName, const QString &colName, const QString &keyCol, const QString &keyValue);
long    getGridInt   (const QString &propName, const QString &colName, const QString &keyCol, const QString &keyValue);
// src/modules/sequencer/sequencer.cpp, SMFocusing()
QString focusProfile = getGridString("focusprofiles", "profile", "filter", QString::number(mCurrentFilterIndex));

One call: “in focusprofiles, the profile column of whichever row has filter equal to the current index” — no intermediate findGridRow(), no index variable to keep around.

The plain, index-based overloads are still the right tool once you already have a row in hand — e.g. a run loop that already tracks mCurrentLine:

// src/modules/sequencer/sequencer.cpp, bumpLiveSequenceCounter()
int count = getGridInt("livesequence", column, mCurrentLine) + 1;
getGridSize(), and the mGlobalDatastore angle

getGridSize(propName) (the row count — findGridRow()’s own loop bound) rounds out the set. All of these are declared public on Basemodule, specifically so they’re also usable as mGlobalDatastore->getGridString(...) to read a grid belonging to another module instance, not just your own — the doc comment next to them says so explicitly. No core module exercises that cross-module form today; every real usage above reads a property belonging to the calling module itself.