Hi anda_skoa,
thank you for replying!!
the model gets it's data from the loadFromFile() method which looks as follows:
bool QCsvTableModel
::loadFromFile(const QString &fileName,
const QChar &delim
) {
beginResetModel();
csvMatrix.clear();
if (delim == 0) {
if (extension.toLower() == "csv")
}
else if (delim
== QChar('"')) return false; //the ONLY invalid delimiter is double quote (")
else
delimiter = delim;
if (!file.isOpen())
if (!file.
open(QFile::ReadOnly|QFile
::Text)) return false;
QList<QString> row;
while (true) {
in >> character;
if (in.atEnd()) {
if (lastCharacter == delimiter) //cases where last character is equal to the delimiter
temp = "";
checkString
(temp, row, csvMatrix, delimiter,
QChar('\n'));
break;
} else if (character
== delimiter || character
== QChar('\n')) checkString(temp, row, csvMatrix, delimiter, character);
else {
temp.append(character);
lastCharacter = character;
}
}
file.close();
in.flush();
in.reset();
return true;
endResetModel();
}
bool QCsvTableModel::loadFromFile(const QString &fileName, const QChar &delim)
{
beginResetModel();
csvMatrix.clear();
QChar delimiter;
QFile file(fileName);
if (delim == 0) {
QString extension = QFileInfo(file).completeSuffix();
if (extension.toLower() == "csv")
delimiter = QChar(';');
}
else if (delim == QChar('"'))
return false; //the ONLY invalid delimiter is double quote (")
else
delimiter = delim;
if (!file.isOpen())
if (!file.open(QFile::ReadOnly|QFile::Text))
return false;
QString temp;
QChar lastCharacter;
QTextStream in(&file);
QList<QString> row;
while (true) {
QChar character;
in >> character;
if (in.atEnd()) {
if (lastCharacter == delimiter) //cases where last character is equal to the delimiter
temp = "";
checkString(temp, row, csvMatrix, delimiter, QChar('\n'));
break;
} else if (character == delimiter || character == QChar('\n'))
checkString(temp, row, csvMatrix, delimiter, character);
else {
temp.append(character);
lastCharacter = character;
}
}
file.close();
in.flush();
in.reset();
return true;
endResetModel();
}
To copy to clipboard, switch view to plain text mode
Bookmarks