client: fix TableModel Region
- Use `uint32_t` as done in server representation - Use rowMin = 1 and rowMax = 0 to represent empty model This is because we cannot set negative values so setting to zero would make empty model and single row models indistinguishable.
Dieser Commit ist enthalten in:
Ursprung
04eed28aa1
Commit
af36c115dc
@ -425,7 +425,7 @@ void Connection::releaseTableModel(TableModel* tableModel)
|
|||||||
tableModel->m_handle = invalidHandle;
|
tableModel->m_handle = invalidHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::setTableModelRegion(TableModel* tableModel, int columnMin, int columnMax, int rowMin, int rowMax)
|
void Connection::setTableModelRegion(TableModel* tableModel, uint32_t columnMin, uint32_t columnMax, uint32_t rowMin, uint32_t rowMax)
|
||||||
{
|
{
|
||||||
auto event = Message::newEvent(Message::Command::TableModelSetRegion);
|
auto event = Message::newEvent(Message::Command::TableModelSetRegion);
|
||||||
event->write(tableModel->handle());
|
event->write(tableModel->handle());
|
||||||
|
|||||||
@ -152,7 +152,7 @@ class Connection : public QObject, public std::enable_shared_from_this<Connectio
|
|||||||
|
|
||||||
[[nodiscard]] int getTableModel(const ObjectPtr& object, std::function<void(const TableModelPtr&, std::optional<const Error>)> callback);
|
[[nodiscard]] int getTableModel(const ObjectPtr& object, std::function<void(const TableModelPtr&, std::optional<const Error>)> callback);
|
||||||
void releaseTableModel(TableModel* tableModel);
|
void releaseTableModel(TableModel* tableModel);
|
||||||
void setTableModelRegion(TableModel* tableModel, int columnMin, int columnMax, int rowMin, int rowMax);
|
void setTableModelRegion(TableModel* tableModel, uint32_t columnMin, uint32_t columnMax, uint32_t rowMin, uint32_t rowMax);
|
||||||
|
|
||||||
[[nodiscard]] int getTileData(Board& object);
|
[[nodiscard]] int getTileData(Board& object);
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ QString TableModel::getValue(int column, int row) const
|
|||||||
return m_texts.value(ColumnRow(column, row));
|
return m_texts.value(ColumnRow(column, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::setRegion(int columnMin, int columnMax, int rowMin, int rowMax)
|
void TableModel::setRegion(uint32_t columnMin, uint32_t columnMax, uint32_t rowMin, uint32_t rowMax)
|
||||||
{
|
{
|
||||||
if(m_region.columnMin != columnMin ||
|
if(m_region.columnMin != columnMin ||
|
||||||
m_region.columnMax != columnMax ||
|
m_region.columnMax != columnMax ||
|
||||||
|
|||||||
@ -45,10 +45,10 @@ class TableModel final : public QAbstractTableModel
|
|||||||
int m_rowCount;
|
int m_rowCount;
|
||||||
struct Region
|
struct Region
|
||||||
{
|
{
|
||||||
int rowMin = 0;
|
uint32_t rowMin = 0;
|
||||||
int rowMax = -1;
|
uint32_t rowMax = -1;
|
||||||
int columnMin = 0;
|
uint32_t columnMin = 0;
|
||||||
int columnMax = -1;
|
uint32_t columnMax = -1;
|
||||||
} m_region;
|
} m_region;
|
||||||
QMap<ColumnRow, QString> m_texts;
|
QMap<ColumnRow, QString> m_texts;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ class TableModel final : public QAbstractTableModel
|
|||||||
QString getRowObjectId(int row) const;
|
QString getRowObjectId(int row) const;
|
||||||
QString getValue(int column, int row) const;
|
QString getValue(int column, int row) const;
|
||||||
|
|
||||||
void setRegion(int columnMin, int columnMax, int rowMin, int rowMax);
|
void setRegion(uint32_t columnMin, uint32_t columnMax, uint32_t rowMin, uint32_t rowMax);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -93,27 +93,39 @@ void TableWidget::updateRegion()
|
|||||||
const int columnCount = m_model->columnCount();
|
const int columnCount = m_model->columnCount();
|
||||||
const int rowCount = m_model->rowCount();
|
const int rowCount = m_model->rowCount();
|
||||||
|
|
||||||
if(columnCount == 0 || rowCount == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QRect r = viewport()->rect();
|
const QRect r = viewport()->rect();
|
||||||
const QModelIndex topLeft = indexAt(r.topLeft());
|
const QModelIndex topLeft = indexAt(r.topLeft());
|
||||||
|
|
||||||
int rowMin = qMax(topLeft.row(), 0);
|
int rowMin = qMax(topLeft.row(), 0);
|
||||||
int rowMax = indexAt(r.bottomLeft()).row();
|
int rowMax = indexAt(r.bottomLeft()).row();
|
||||||
if(rowMax == -1)
|
|
||||||
|
if(rowCount == 0)
|
||||||
|
{
|
||||||
|
// Invalid region to represent empty model
|
||||||
|
rowMin = 1;
|
||||||
|
rowMax = 0;
|
||||||
|
}
|
||||||
|
else if(rowMax == -1)
|
||||||
rowMax = rowCount - 1;
|
rowMax = rowCount - 1;
|
||||||
else
|
else
|
||||||
rowMax = qMin(rowMax + 1, rowCount - 1);
|
rowMax = qMin(rowMax + 1, rowCount - 1);
|
||||||
|
|
||||||
int columnMin = qMax(topLeft.column(), 0);
|
int columnMin = qMax(topLeft.column(), 0);
|
||||||
int columnMax = indexAt(r.topRight()).column();
|
int columnMax = indexAt(r.topRight()).column();
|
||||||
|
|
||||||
|
if(columnCount == 0)
|
||||||
|
{
|
||||||
|
// Invalid region to represent empty model
|
||||||
|
columnMin = 1;
|
||||||
|
columnMax = 0;
|
||||||
|
}
|
||||||
if(columnMax == -1)
|
if(columnMax == -1)
|
||||||
columnMax = columnCount - 1;
|
columnMax = columnCount - 1;
|
||||||
else
|
else
|
||||||
columnMax = qMin(columnMax + 1, columnCount - 1);
|
columnMax = qMin(columnMax + 1, columnCount - 1);
|
||||||
|
|
||||||
m_model->setRegion(columnMin, columnMax, rowMin, rowMax);
|
m_model->setRegion(uint32_t(columnMin), uint32_t(columnMax),
|
||||||
|
uint32_t(rowMin), uint32_t(rowMax));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableWidget::mouseMoveEvent(QMouseEvent* event)
|
void TableWidget::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
|||||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren