MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / addTable

Method addTable

app/src/DataModel/ProjectModel.cpp:5252–5281  ·  view source on GitHub ↗

* @brief Adds a new empty data table with a leaf name unique within @p parentFolderId; returns its * full folder-qualified path. */

Source from the content-addressed store, hash-verified

5250 * full folder-qualified path.
5251 */
5252QString 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.

Callers 1

tableAddMethod · 0.80

Calls 3

folderExistsFunction · 0.85
isEmptyMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected