I am not sure why I thought the quotes would not be included in the strings, unless it is because I am just used to thinking they should be there, when I add a string. Once I found QStringList::replaceInStrings(), the problem was solved.
while(!bomIn.atEnd())
{
rowList.replaceInStrings("\"", "");
bomData.append(rowList);
}
while(!bomIn.atEnd())
{
QString line = bomIn.readLine();
QStringList rowList = line.split(';');
rowList.replaceInStrings("\"", "");
bomData.append(rowList);
}
To copy to clipboard, switch view to plain text mode
I originally thought to use separate lists, for the headers and data, but that would have meant adding two arguments to the constructor, instead of just one, plus adding another structure to keep track of. I ended up implementing data() like this:
{
if(role == Qt::DisplayRole)
{
return row.at(index.column());
}
}
QVariant BomTableMode::data(const QModelIndex &index, int role) const
{
if(role == Qt::DisplayRole)
{
QStringList row = rowList.at(index.row() + 1);
return row.at(index.column());
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
and headerData() like this:
QVariant BomTableMode
::headerData(int section, Qt
::Orientation orientation,
int role
) const {
if(role != Qt::DisplayRole)
if(orientation == Qt::Horizontal)
{
return column.at(section);
}
}
QVariant BomTableMode::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role != Qt::DisplayRole)
return QVariant();
if(orientation == Qt::Horizontal)
{
QStringList column = rowList.at(0);
return column.at(section);
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
I did similar with rowCount() and columnCount(). I think magic numbers are OK here, since it is easy to understand that the first list is the headers. Except for forgetting to type an "l" at the end of my class name , it seems to be working. Thanks, both of you.
I did notice at least one of the fields can end up being too long, so I am going to have to implement word wrapping somehow. I assume that is either the view, or the delegate.
Bookmarks