MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / varSaveSelectedFiles

Method varSaveSelectedFiles

gui/qt/mainwindow.cpp:2036–2106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2034}
2035
2036void MainWindow::varSaveSelectedFiles() {
2037 QFileDialog dialog(this);
2038 dialog.setFileMode(QFileDialog::Directory);
2039 dialog.setOption(QFileDialog::ShowDirsOnly, true);
2040
2041 dialog.setDirectory(m_dir);
2042 int good = 0;
2043
2044 for (int currRow = 0; currRow < ui->emuVarView->model()->rowCount(); currRow++) {
2045 if (ui->emuVarView->model()->index(currRow, VarTableModel::VAR_NAME_COL).data(Qt::CheckStateRole) == Qt::Checked) {
2046 good = 1;
2047 break;
2048 }
2049 }
2050
2051 if (!good) {
2052 QMessageBox::warning(this, MSG_WARNING, tr("Select at least one file to transfer"));
2053 return;
2054 }
2055
2056 good = dialog.exec();
2057 m_dir.setPath(dialog.directory().absolutePath());
2058
2059 if (!good) {
2060 return;
2061 }
2062
2063 varReceive([this, dir = dialog.directory().absolutePath()](bool isBlocked) {
2064 QString name;
2065 QString filename;
2066 QString errMsg;
2067
2068 for (int currRow = 0; currRow < ui->emuVarView->model()->rowCount(); currRow++) {
2069 QModelIndex nameIndex = ui->emuVarView->model()->index(currRow, VarTableModel::VAR_NAME_COL);
2070 if (nameIndex.data(Qt::CheckStateRole) == Qt::Checked) {
2071 calc_var_t var, varName = nameIndex.data(Qt::UserRole).value<calc_var_t>();
2072 // Find the variable first to ensure the current type is used for the file extension
2073 if (!vat_search_find(&varName, &var)) {
2074 if (calc_var_is_list(&varName)) {
2075 // Remove any linked formula before generating filename
2076 varName.name[varName.namelen - 1] = 0;
2077 }
2078 name = QString(calc_var_name_to_utf8(varName.name, varName.namelen, varName.named));
2079 errMsg = tr("Transfer error, variable no longer exists: ") + name;
2080 break;
2081 }
2082 if (calc_var_is_list(&var)) {
2083 // Remove any linked formula before generating filename
2084 var.name[var.namelen - 1] = 0;
2085 }
2086
2087 name = QString(calc_var_name_to_utf8(var.name, var.namelen, var.named));
2088 filename = dir + "/" + name + "." + m_varExtensions[var.type];
2089
2090 if (emu_receive_variable(filename.toStdString().c_str(), &var, 1) != LINK_GOOD) {
2091 errMsg = tr("Transfer error, see console for information:\nFile: ") + filename;
2092 break;
2093 }

Callers

nothing calls this directly

Calls 8

vat_search_findFunction · 0.85
calc_var_is_listFunction · 0.85
QStringClass · 0.85
calc_var_name_to_utf8Function · 0.85
emu_receive_variableFunction · 0.85
rowCountMethod · 0.80
unblockMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected