MCPcopy Create free account
hub / github.com/KDAB/KDChart / saveFile

Method saveFile

examples/ModelView/TableView/mainwindow.cpp:205–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205void MainWindow::saveFile()
206{
207 QString fileName = QFileDialog::getSaveFileName(this, tr("Save file as"), "", "*.cht");
208
209 if (!fileName.isEmpty()) {
210 QFile file(fileName);
211 QTextStream stream(&file);
212
213 if (file.open(QFile::WriteOnly | QFile::Text)) {
214 for (int row = 0; row < m_model->rowCount(QModelIndex()); ++row) {
215
216 QStringList pieces;
217
218 pieces.append(m_model->data(m_model->index(row, 0, QModelIndex()),
219 Qt::DisplayRole)
220 .toString());
221 pieces.append(m_model->data(m_model->index(row, 1, QModelIndex()),
222 Qt::DisplayRole)
223 .toString());
224 pieces.append(m_model->data(m_model->index(row, 2, QModelIndex()),
225 Qt::DisplayRole)
226 .toString());
227 pieces.append(m_model->data(m_model->index(row, 0, QModelIndex()),
228 Qt::DecorationRole)
229 .toString());
230
231 stream << pieces.join(",") << "\n";
232 }
233 }
234
235 file.close();
236 statusBar()->showMessage(tr("Saved %1").arg(fileName), 2000);
237 }
238}

Callers

nothing calls this directly

Calls 5

QModelIndexClass · 0.50
isEmptyMethod · 0.45
rowCountMethod · 0.45
dataMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected