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