* @brief Adds a new empty data table with a leaf name unique within @p parentFolderId; returns its * full folder-qualified path. */
| 5250 | * full folder-qualified path. |
| 5251 | */ |
| 5252 | QString DataModel::ProjectModel::addTable(const QString& name, int parentFolderId) |
| 5253 | { |
| 5254 | if (parentFolderId != -1 && !folderExists(m_tableFolders, parentFolderId)) |
| 5255 | parentFolderId = -1; |
| 5256 | |
| 5257 | QString base = name.simplified().remove(QLatin1Char('/')); |
| 5258 | if (base.isEmpty()) |
| 5259 | base = tr("Shared Table"); |
| 5260 | |
| 5261 | QString unique = base; |
| 5262 | int suffix = 2; |
| 5263 | const auto hasLeaf = [this, parentFolderId](const QString& n) { |
| 5264 | for (const auto& t : m_tables) |
| 5265 | if (t.parentFolderId == parentFolderId && t.name == n) |
| 5266 | return true; |
| 5267 | |
| 5268 | return false; |
| 5269 | }; |
| 5270 | |
| 5271 | while (hasLeaf(unique)) |
| 5272 | unique = QStringLiteral("%1 %2").arg(base, QString::number(suffix++)); |
| 5273 | |
| 5274 | DataModel::TableDef table; |
| 5275 | table.name = unique; |
| 5276 | table.parentFolderId = parentFolderId; |
| 5277 | m_tables.push_back(table); |
| 5278 | setModified(true); |
| 5279 | Q_EMIT tablesChanged(); |
| 5280 | return tablePathFor(table); |
| 5281 | } |
| 5282 | |
| 5283 | /** |
| 5284 | * @brief Deletes the table with the given full path. |
no test coverage detected