0

I have this table view in which I add different items on 3 columns. The items are editable so I can modify them directly in the view.


    bool ClothoidTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
    {
        if (index.isValid() && role == Qt::EditRole) {
            int row = index.row();

            ClothoidCurve p = listOfCurves.value(row);

            if (index.column() == 0)
                p.length = value.toFloat();            
            else if (index.column() == 1)
                p.startCurvature = value.toFloat();
            else if (index.column() == 2)
                p.endCurvature = value.toFloat();
            else
                return false;

            listOfCurves.replace(row, p);
            emit(dataChanged(index, index));

            return true;
        }

        return false;
    }

The method above is declared in my table model and it is called both when I add and when I modify the data in the table.

I would like to send a signal only when I modify the items in the table.How could I do that? Is there any way to differentiate between addition and modification?

schmimona
  • 849
  • 3
  • 20
  • 40

1 Answers1

0

How and where do you want to know about the difference? Well-behaved models emit rowsAboutToBeInserted and rowsInserted before and after new data is added. I would think (although I'm not sure) that the setting of data for the new rows should happen between these calls. It's worth a shot, anyway. Otherwise, you might be able to track the rows that were last inserted, and use that to distinguish between "adding" and "editing". It would be imperfect, but probably cover most of your use cases.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49