92 QString DocumentManager::makeNewModelName() |
92 QString DocumentManager::makeNewModelName() |
93 { |
93 { |
94 untitledNameCounter += 1; |
94 untitledNameCounter += 1; |
95 return "untitled-" + QString::number(untitledNameCounter); |
95 return "untitled-" + QString::number(untitledNameCounter); |
96 } |
96 } |
|
97 |
|
98 void DocumentManager::loadDependenciesForModel( |
|
99 const QString& modelName, |
|
100 const LibraryManager& libraries, |
|
101 QTextStream& errorStream) |
|
102 { |
|
103 QStringList missing; |
|
104 QStringList processed; |
|
105 loadDependenciesForModel(modelName, libraries, missing, processed, errorStream); |
|
106 if (not missing.empty()) |
|
107 { |
|
108 missing.sort(Qt::CaseInsensitive); |
|
109 errorStream << utility::format( |
|
110 "The following files could not be opened: %1", |
|
111 missing.join(", ")); |
|
112 } |
|
113 } |
|
114 |
|
115 void DocumentManager::loadDependenciesForModel( |
|
116 const QString& modelName, |
|
117 const LibraryManager& libraries, |
|
118 QStringList& missing, |
|
119 QStringList& processed, |
|
120 QTextStream& errorStream) |
|
121 { |
|
122 struct LoadingError |
|
123 { |
|
124 QString message; |
|
125 }; |
|
126 processed.append(modelName); |
|
127 Model* model = this->findModelByName(modelName); |
|
128 for (int i = 0; i < model->size(); i += 1) |
|
129 { |
|
130 const QString referenceName = model->getObjectProperty(i, modelobjects::Property::ReferenceName).toString(); |
|
131 if (not referenceName.isEmpty() |
|
132 and openModels.find(referenceName) == std::end(openModels) |
|
133 and not missing.contains(referenceName)) |
|
134 { |
|
135 try |
|
136 { |
|
137 const QString path = libraries.findFile(referenceName); |
|
138 if (path.isEmpty()) |
|
139 { |
|
140 throw LoadingError{utility::format("'%1' was not found.", referenceName)}; |
|
141 } |
|
142 QString errorString; |
|
143 QTextStream localErrorStream{&errorString}; |
|
144 QString resultName = this->openModel(path, localErrorStream); |
|
145 if (resultName.isEmpty()) |
|
146 { |
|
147 throw LoadingError{utility::format( |
|
148 "could not load '%1': %2", |
|
149 path, |
|
150 errorString)}; |
|
151 } |
|
152 if (not processed.contains(referenceName)) |
|
153 { |
|
154 loadDependenciesForModel(referenceName, libraries, missing, processed, errorStream); |
|
155 } |
|
156 } |
|
157 catch(const LoadingError& error) |
|
158 { |
|
159 errorStream << error.message << "\n"; |
|
160 missing.append(referenceName); |
|
161 processed.append(referenceName); |
|
162 } |
|
163 } |
|
164 } |
|
165 } |