/** * Update any defined calculations to reflect the deletion of a column. * * @param name The name of the column that was deleted */ void DBEditor::deleteColumnRefs(const QString &name) { NameCalcMap::Iterator iter; QStringList deletions; for (iter = calcMap.begin(); iter != calcMap.end(); ++iter) { QString calcName = iter.key(); CalcNode *calcRoot = iter.value(); if (calcRoot != 0) { int index = info.Find(ceName [calcName.toUtf8()]); if (calcRoot->deleteColumn(name)) { delete calcRoot; deletions.append(calcName); ceDefault (info[index]) = ""; } else { ceDefault (info[index]) = calcRoot->equation().toUtf8(); } } } int count = deletions.count(); for (int i = 0; i < count; i++) { calcMap.remove(deletions[i]); calcMap.insert(deletions[i], 0); } }
/** * Launch this dialog in order to edit the format of the specified database. * * @param subject The database whose format is to be edited */ int DBEditor::edit(Database *subject) { db = subject; columnEditor = new ColumnEditor(db, this); originalCols = db->listColumns(); renamedCols = db->listColumns(); int count = originalCols.count(); for (int i = 0; i < count; i++) { QString name = originalCols[i]; int type = db->getType(name); QString defaultVal = db->getDefault(name); if (type == CALC) { int decimals = 2; CalcNode *root = db->loadCalc(name, &decimals); calcMap.insert(name, root); decimalsMap.insert(name, decimals); if (root != 0) { defaultVal = root->equation(db); } } info.Add(ceName [name.toUtf8()] + ceType [type] + ceDefault [defaultVal.toUtf8()] + ceOldIndex [i] + ceNewIndex [i]); } updateTable(); return exec(); }
/** * Update any defined calculations to reflect a column renaming. * * @param oldName The old column name * @param newName The new column name */ void DBEditor::renameColumnRefs(const QString &oldName, const QString &newName) { NameCalcMap::Iterator iter; for (iter = calcMap.begin(); iter != calcMap.end(); ++iter) { QString calcName = iter.key(); CalcNode *calcRoot = iter.value(); if (calcRoot != 0) { int index = info.Find(ceName [calcName.toUtf8()]); calcRoot->renameColumn(oldName, newName); ceDefault (info[index]) = calcRoot->equation().toUtf8(); } } }