MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / exportEntries

Method exportEntries

src/openms_gui/source/VISUAL/TableView.cpp:82–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 void TableView::exportEntries()
83 {
84 QString filename = QFileDialog::getSaveFileName(this, "Save File", "", "tsv file (*.tsv)");
85 QFile f(filename);
86
87 if (!f.open(QIODevice::WriteOnly))
88 {
89 throw Exception::FileNotWritable(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String(filename));
90 }
91 QTextStream ts(&f);
92 QStringList str_list;
93
94 QStringList cols_to_export = (getHeaderNames(WidgetHeader::VISIBLE_ONLY, true) + mandatory_export_columns_);
95 cols_to_export.removeDuplicates();
96
97 QStringList all_header_names = getHeaderNames(WidgetHeader::WITH_INVISIBLE, true);
98
99 // write header
100 bool first{true};
101 for (int c = 0; c < columnCount(); ++c)
102 {
103 // columns marked for export
104 if (cols_to_export.indexOf(all_header_names[c]) != -1)
105 {
106 if (!first)
107 {
108 ts << "\t";
109 }
110 else
111 {
112 first = false;
113 }
114 ts << all_header_names[c];
115 }
116 }
117 ts << "\n";
118
119 // write entries
120 for (int r = 0; r < rowCount(); ++r)
121 {
122 for (int c = 0; c < columnCount(); ++c)
123 {
124 // only export columns we marked for export
125 if (cols_to_export.indexOf(all_header_names[c]) == -1)
126 {
127 continue;
128 }
129
130 QTableWidgetItem* ti = this->item(r, c);
131 if (ti == nullptr)
132 {
133 str_list << "";
134 std::cerr << "Warning: Empty table cell found at position: ["<< r << ' ' << c << "]\n";
135 }
136 else
137 {
138 if (ti->data(Qt::UserRole).isValid())
139 {

Callers

nothing calls this directly

Calls 6

StringClass · 0.50
openMethod · 0.45
isValidMethod · 0.45
toStringMethod · 0.45
clearMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected