Items are loaded from default JSON file in standard location at startup. If no items are found in file, example items are generated.
This commit is contained in:
@ -90,6 +90,10 @@ QUndoStack* GenericCore::getModelUndoStack() const { return m_modelUndoStack; }
|
||||
|
||||
std::shared_ptr<TableModel> GenericCore::getModel() const { return m_mainModel; }
|
||||
|
||||
/**
|
||||
* Save items to default file (in standard location).
|
||||
* @brief GenericCore::saveItems Saves item fo file.
|
||||
*/
|
||||
void GenericCore::saveItems() {
|
||||
qDebug() << "saving items...";
|
||||
|
||||
@ -108,6 +112,29 @@ void GenericCore::saveItems() {
|
||||
void GenericCore::setupModels() {
|
||||
m_mainModel = make_shared<TableModel>(m_modelUndoStack, this);
|
||||
// TODO add QAbstractItemModelTester
|
||||
initModelData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializing model with data. Tries to read items from default file. Generating example items as
|
||||
* fallback.
|
||||
* @brief GenericCore::initModelData
|
||||
*/
|
||||
void GenericCore::initModelData() {
|
||||
qInfo() << "Trying to read model data from file...";
|
||||
const QByteArray jsonDoc = FileHandler::loadJSONDataFromFile("items.json");
|
||||
// qDebug() << "jsonDoc:" << jsonDoc;
|
||||
// TODO decide on lack of file(s) (config, data) if example items should be generated
|
||||
// (see welcome wizard)
|
||||
if (jsonDoc.isEmpty()) {
|
||||
qDebug() << "No item content in file. Generating example items...";
|
||||
const QByteArray exampleItems = m_mainModel->generateExampleItems();
|
||||
m_mainModel->insertItems(0, exampleItems);
|
||||
} else {
|
||||
qDebug() << "Item in file found.";
|
||||
m_mainModel->insertItems(0, jsonDoc);
|
||||
}
|
||||
m_modelUndoStack->clear();
|
||||
}
|
||||
|
||||
QString GenericCore::getMaintenanceToolFilePath() const {
|
||||
|
||||
Reference in New Issue
Block a user