[Development] Qt6 source changes

Иван Комиссаров abbapoh at gmail.com
Sat Nov 3 03:16:38 CET 2018


Sure. Sorry for std::array_view (it maybe a QSet or QVector or gsl::span whatever more convinient/faster).
The basic idea is here:

In the model:
void multipleData(QModelIndex index, std::array_view<Qt::ItemRole> roles, std::function<void(Qt::ItemRole,QVariant)> enumerator)
{
   for (auto&& role: roles) {
      if (role == Qt::DisplayRole) {
          enumerator(role, data.at(index.row()).text);
      if (role == Qt::EditRole) {
          enumerator(role, data.at(index.row()).editText);
      }
      // ….
   }
}

In the view:
QMap<Qt::ItemRole, QVariant> map
auto enumerator = [&map](Qt::ItemRole role, QVariant data) {
    map[role] = data; // actually here’s the view’s code, painting data and so on, no need in intermediate container, I use it just for example
}
model->multipleData(index, {Qt::DisplayRole, Qt::BackgroundRole}, enumerator);

Not sure if std::function does not allocate in case of lambda, btw. I 80% sure it does, so returning a vector can be better. Anyway, one can look at the assembly in both cases and run a profiler.

> 3 нояб. 2018 г., в 1:25, Giuseppe D'Angelo <giuseppe.dangelo at kdab.com> написал(а):
> 
> Mind to elaborate on the std::function idea?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181103/2dff608b/attachment.html>


More information about the Development mailing list