fixed warning + added more checks to SignalVectorModel

This commit is contained in:
fourtf 2019-09-11 13:12:08 +02:00
parent 2a8c5e654f
commit 2f39f4246c

View file

@ -102,19 +102,26 @@ public:
int rowCount(const QModelIndex &parent) const override
{
(void)parent;
return this->rows_.size();
}
int columnCount(const QModelIndex &parent) const override
{
(void)parent;
return this->columnCount_;
}
QVariant data(const QModelIndex &index, int role) const override
{
int row = index.row(), column = index.column();
assert(row >= 0 && row < this->rows_.size() && column >= 0 &&
column < this->columnCount_);
if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_)
{
return QVariant();
}
return rows_[row].items[column]->data(role);
}
@ -123,8 +130,11 @@ public:
int role) override
{
int row = index.row(), column = index.column();
assert(row >= 0 && row < this->rows_.size() && column >= 0 &&
column < this->columnCount_);
if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_)
{
return false;
}
Row &rowItem = this->rows_[row];
@ -186,7 +196,9 @@ public:
{
int row = index.row(), column = index.column();
if (row < 0 || column < 0) {
if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_)
{
return Qt::NoItemFlags;
}
@ -212,6 +224,8 @@ public:
bool removeRows(int row, int count, const QModelIndex &parent) override
{
(void)parent;
if (count != 1)
{
return false;
@ -242,18 +256,22 @@ protected:
std::vector<QStandardItem *> &row,
int proposedIndex)
{
(void)item, (void)row;
return proposedIndex;
}
virtual void afterRemoved(const TVectorItem &item,
std::vector<QStandardItem *> &row, int index)
{
(void)item, (void)row, (void)index;
}
virtual void customRowSetData(const std::vector<QStandardItem *> &row,
int column, const QVariant &value, int role,
int rowIndex)
{
(void)row, (void)column, (void)value, (void)role, (void)rowIndex;
}
void insertCustomRow(std::vector<QStandardItem *> row, int index)