Havoc][
17th June 2009, 20:29
I have Subclassed (i hope you call my doing "subclass", in dont now exactly!) a QSqlRelationTableModel to prepare some Strings in my QTableView.
Here is the Code:
QVariant qtbooksqlrelationmodel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlRelationalTableModel::data(index, role);
if (value.isValid() && role == Qt::DisplayRole)
{
if (index.column() == 1)
{
if (QDateTime::fromString(value.toString(), "yyyy-MM-dd").isValid())
{
return QString((QDateTime::fromString(value.toString(), "yyyy-MM-dd").toString("dd.MM.yyyy")));
}
else if (value == iFixkosten_JEDEN_MONAT )
{
return qApp->trUtf8("Jeden Monat");
}
else if (value == iFixkosten_JEDE_WOCHE )
{
return qApp->trUtf8("Jeden Woche");
}
}
else if (index.column() == 3)
{
check_Kategorie_ist_einnahme(index.model()->index(index.row(), 3));
return value.toString().prepend(QString::fromUtf8("+")).append(QString::fromUtf8(" €"));
}
}
//if (role == Qt::TextColorRole && index.column() == 1)
// return qVariantFromValue(QColor(Qt::blue));
return value;
}
(Sorry, for the German Variable-Names)
Now, for better understanding:
I have two Columns:
category | price
1 | 3,40€
2 | 5,70€
6 | 14,69€
and so one.
Now i want to prepare the price value related to its category.
If its category 6 i want to value.prepend(QString::fromUtf8("+")), if not i want value.prepend(QString::fromUtf8("-")).
How could i get the value of column 1 if iam "in" column 2? Is there any way?
I tried something like:
index.model()->index(index.row(), 1).data().toString()
But after that, my Application died with this Message:
The program has unexpectedly finished.
Thanks in advanced.
Havoc][
Here is the Code:
QVariant qtbooksqlrelationmodel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlRelationalTableModel::data(index, role);
if (value.isValid() && role == Qt::DisplayRole)
{
if (index.column() == 1)
{
if (QDateTime::fromString(value.toString(), "yyyy-MM-dd").isValid())
{
return QString((QDateTime::fromString(value.toString(), "yyyy-MM-dd").toString("dd.MM.yyyy")));
}
else if (value == iFixkosten_JEDEN_MONAT )
{
return qApp->trUtf8("Jeden Monat");
}
else if (value == iFixkosten_JEDE_WOCHE )
{
return qApp->trUtf8("Jeden Woche");
}
}
else if (index.column() == 3)
{
check_Kategorie_ist_einnahme(index.model()->index(index.row(), 3));
return value.toString().prepend(QString::fromUtf8("+")).append(QString::fromUtf8(" €"));
}
}
//if (role == Qt::TextColorRole && index.column() == 1)
// return qVariantFromValue(QColor(Qt::blue));
return value;
}
(Sorry, for the German Variable-Names)
Now, for better understanding:
I have two Columns:
category | price
1 | 3,40€
2 | 5,70€
6 | 14,69€
and so one.
Now i want to prepare the price value related to its category.
If its category 6 i want to value.prepend(QString::fromUtf8("+")), if not i want value.prepend(QString::fromUtf8("-")).
How could i get the value of column 1 if iam "in" column 2? Is there any way?
I tried something like:
index.model()->index(index.row(), 1).data().toString()
But after that, my Application died with this Message:
The program has unexpectedly finished.
Thanks in advanced.
Havoc][