When receiving online user credentials insert them into the model.
This commit is contained in:
@ -231,6 +231,14 @@ bool TableModel::updateItem(const ModelItemValues& itemValues) {
|
||||
}
|
||||
}
|
||||
|
||||
void TableModel::setOnlineCredentials(const QString& mail,
|
||||
const QString& uuid,
|
||||
const QString& token) {
|
||||
QModelIndex itemIndex = getIndexByRoleValue(mail, MailRole);
|
||||
setItemData(itemIndex, {{OnlineIdRole, uuid}, {AccessCodeRole, token}});
|
||||
}
|
||||
|
||||
|
||||
bool TableModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) {
|
||||
if (parentIndex != QModelIndex()) {
|
||||
qWarning() << "Removing of child rows is not supported yet!";
|
||||
@ -282,29 +290,6 @@ void TableModel::insertItems(int startPosition,
|
||||
m_undoStack->push(insertCommand);
|
||||
}
|
||||
|
||||
void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int last) {
|
||||
Q_UNUSED(first);
|
||||
Q_UNUSED(last);
|
||||
|
||||
if (parent != QModelIndex()) {
|
||||
return;
|
||||
}
|
||||
emit rowCountChanged();
|
||||
emit nExpectedBiddingsChanged();
|
||||
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
|
||||
int TableModel::nExpectedBiddings() const {
|
||||
int result = 0;
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
@ -352,6 +337,29 @@ qreal TableModel::biddingAverage3() const {
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
void TableModel::onRowCountChanged(const QModelIndex& parent, int first, int last) {
|
||||
Q_UNUSED(first);
|
||||
Q_UNUSED(last);
|
||||
|
||||
if (parent != QModelIndex()) {
|
||||
return;
|
||||
}
|
||||
emit rowCountChanged();
|
||||
emit nExpectedBiddingsChanged();
|
||||
|
||||
emit nPlacedBiddingsChanged(1);
|
||||
emit nPlacedBiddingsChanged(2);
|
||||
emit nPlacedBiddingsChanged(3);
|
||||
|
||||
emit biddingSumChanged(1);
|
||||
emit biddingSumChanged(2);
|
||||
emit biddingSumChanged(3);
|
||||
|
||||
emit biddingAverageChanged(1);
|
||||
emit biddingAverageChanged(2);
|
||||
emit biddingAverageChanged(3);
|
||||
}
|
||||
|
||||
void TableModel::execInsertItems(const int firstRow, const QList<ModelItemValues> valueList) {
|
||||
const int nRows = valueList.size();
|
||||
qDebug() << "Inserting" << nRows << "items...";
|
||||
@ -387,7 +395,6 @@ void TableModel::execEditItemData(const int row, const QMap<int, QVariant>& chan
|
||||
roles.insert(0, Qt::DisplayRole);
|
||||
emit dataChanged(firstIndex, lastIndex, roles.toVector());
|
||||
|
||||
// NEXT check which roles are changed & trigger only changed properties
|
||||
if (roles.contains(BiddingTypeRole) || roles.contains(ShareAmountRole) ||
|
||||
roles.contains(ShareTypeRole)) {
|
||||
emit nExpectedBiddingsChanged();
|
||||
@ -576,3 +583,29 @@ qreal TableModel::totalSharesWithBiddings(const UserRoles biddingRole) const {
|
||||
qInfo() << "Biddings exist for " << result << "shares!";
|
||||
return result;
|
||||
}
|
||||
|
||||
QModelIndex TableModel::getIndexByRoleValue(const QString& valueString, const int role) const {
|
||||
const QString text =
|
||||
QString("Searching list item with value '%1' for role '%2'").arg(valueString, role);
|
||||
qInfo() << text;
|
||||
int itemRow = -1;
|
||||
|
||||
for (auto i = m_items.begin(), end = m_items.end(); i != end; ++i) {
|
||||
const QString mailValue = (*i)->data(role).toString();
|
||||
qDebug() << "found value:" << mailValue;
|
||||
if (valueString == mailValue) {
|
||||
itemRow = i - m_items.constBegin();
|
||||
qInfo() << "Found item at row:" << itemRow;
|
||||
break;
|
||||
} else {
|
||||
qDebug() << "Not the right item. Continuing search...";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (itemRow < 0 || itemRow >= m_items.length()) {
|
||||
qWarning() << "Couldn't find item with mail address:" << valueString << "- Returning...";
|
||||
return QModelIndex();
|
||||
}
|
||||
const QModelIndex itemIndex = index(itemRow, 0);
|
||||
return itemIndex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user