Commit f6819f91 authored by Alexander Semke's avatar Alexander Semke

[json import] further fixes and optimizations:

1. create QJsonModel in JsonFilter when executing the tests since no
model is available in this case.
2. use the already available full JSON document in the prepare step when
the root element is selected, no need to re-create it again.
parent 95072f26
......@@ -440,17 +440,27 @@ int JsonFilterPrivate::prepareDeviceToRead(QIODevice& device) {
*/
bool JsonFilterPrivate::prepareDocumentToRead() {
PERFTRACE("Prepare the JSON document to read");
if (modelRows.isEmpty())
m_preparedDoc = m_doc;
else {
if (!model)
model->loadJson(m_doc);
if (modelRows.size() == 1)
m_preparedDoc = m_doc; //root element selected, use the full document
else {
//when running tests there is no ImportFileWidget and JsonOptionsWidget available
//where the model is created and also passed to JsonFilter. So, we need to create
//a model here for in this case.
if (!model) {
model = new QJsonModel();
model->loadJson(m_doc);
}
QModelIndex index;
for (auto& it : modelRows)
index = model->index(it, 0, index);
QModelIndex index;
for (auto& it : modelRows)
index = model->index(it, 0, index);
m_preparedDoc = model->genJsonByIndex(index);
m_preparedDoc = model->genJsonByIndex(index);
}
}
if (!m_preparedDoc.isEmpty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment