Simple implementation of CSV file import. Successfully imported items are appended to the model.
This commit is contained in:
@ -169,18 +169,26 @@ void TableModel::appendItems(const QByteArray& jsonDoc) { insertItems(-1, jsonDo
|
||||
void TableModel::insertItems(int startPosition,
|
||||
const QByteArray& jsonDoc,
|
||||
const QModelIndex& parentIndex) {
|
||||
const QList<QHash<int, QVariant>> valueList =
|
||||
JsonParser::toItemValuesList(jsonDoc, ITEM_KEY_STRING);
|
||||
|
||||
insertItems(startPosition, valueList, parentIndex);
|
||||
}
|
||||
|
||||
void TableModel::insertItems(int startPosition,
|
||||
const QList<QHash<int, QVariant>>& itemValuesList,
|
||||
const QModelIndex& parentIndex) {
|
||||
qInfo() << "Inserting item(s) into model...";
|
||||
if (parentIndex != QModelIndex()) {
|
||||
qWarning() << "Using invalid parent index (no child support for now)";
|
||||
qWarning()
|
||||
<< "Using invalid parent index (no child support for now)! Using root index as parent...";
|
||||
}
|
||||
if (startPosition == -1 || startPosition > m_items.size()) {
|
||||
/// Appending item(s)
|
||||
startPosition = m_items.size();
|
||||
}
|
||||
|
||||
QList<QHash<int, QVariant>> valueList = JsonParser::toItemValuesList(jsonDoc, ITEM_KEY_STRING);
|
||||
|
||||
InsertRowsCommand* insertCommand = new InsertRowsCommand(this, startPosition, valueList);
|
||||
InsertRowsCommand* insertCommand = new InsertRowsCommand(this, startPosition, itemValuesList);
|
||||
m_undoStack->push(insertCommand);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user