63 if (!path.contains(
".sel"))
70 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
71 qDebug() <<
"Error opening selection file";
76 QTextStream in(&file);
79 QString line = in.readLine();
81 if (line.contains(
"%") ==
false && line.contains(
":") ==
true)
83 QStringList firstSplit = line.split(
":");
86 QString key = firstSplit.at(0);
88 QStringList secondSplit = firstSplit.at(1).split(
"|");
91 if (secondSplit.at(secondSplit.size() - 1) ==
"")
92 secondSplit.removeLast();
95 selectionMap.insert(key, secondSplit);
109 if (path.find(
".sel") == std::string::npos)
113 selectionMap.clear();
115 std::ifstream inFile(path);
116 if (!inFile.is_open()) {
117 qDebug() <<
"Error opening selection file";
123 while (std::getline(inFile, line)) {
124 if (line.find(
'%') == std::string::npos && line.find(
':') != std::string::npos) {
126 auto colonPos = line.find(
':');
127 std::string key = line.substr(0, colonPos);
128 std::string channelsPart = line.substr(colonPos + 1);
131 std::vector<std::string> channels;
132 std::stringstream stream{channelsPart};
134 while (std::getline(stream, token,
'|')) {
135 channels.push_back(token);
139 if (!channels.empty() && channels.back().empty()) {
143 selectionMap.insert({key, channels});
155 if (!path.contains(
".mon"))
159 selectionMap.clear();
162 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
163 qDebug() <<
"Error opening montage file";
168 QTextStream in(&file);
169 QString groupName = in.readLine();
170 QStringList channels;
172 while (!in.atEnd()) {
173 QString line = in.readLine();
175 if (line.contains(
":") ==
true) {
176 QStringList secondSplit = line.split(
":");
177 QString key = secondSplit.at(0);
178 channels.append(key);
183 selectionMap.insert(groupName, channels);
195 if (path.find(
".mon") == std::string::npos)
199 selectionMap.clear();
201 std::ifstream inFile(path);
202 if (!inFile.is_open()) {
203 qDebug() <<
"Error opening montage file";
206 std::vector<std::string> channels;
208 std::string groupName;
209 std::getline(inFile, groupName);
212 while (std::getline(inFile, line)) {
213 if (line.find(
':') != std::string::npos) {
214 auto colonPos = line.find(
':');
215 std::string channelName = line.substr(0, colonPos);
216 channels.push_back(channelName);
220 selectionMap.insert({groupName, channels});
230 if (!path.contains(
".sel"))
234 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
235 qDebug() <<
"Error opening sel file for writing";
240 QTextStream out(&file);
242 QMultiMap<QString, QStringList>::const_iterator i = selectionMap.constBegin();
243 while (i != selectionMap.constEnd()) {
244 out << i.key() <<
":";
246 for (
int u = 0; u < i.value().size(); u++)
247 out << i.value().at(u) <<
"|";
265 if (path.find(
".sel") == std::string::npos)
268 std::ofstream outFile(path);
269 if (!outFile.is_open()) {
270 qDebug() <<
"Error opening sel file for writing";
274 for (
auto& mapElement : selectionMap) {
275 outFile << mapElement.first <<
":";
276 for (
auto& vectorElement : mapElement.second) {
277 outFile << vectorElement <<
"|";
290 for (
auto i = selectionMap.constBegin(); i != selectionMap.constEnd(); i++) {
291 QFileInfo fileInfo(path);
293 QString newPath = QString(
"%1/%2.mon").arg(fileInfo.absolutePath()).arg(i.key());
298 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
299 qDebug() <<
"Error opening mon file for writing";
304 QTextStream out(&file);
306 out << i.key() <<
"\n";
308 for (
int u = 0; u < i.value().size(); u++)
309 out << i.value().at(u) <<
" : " << i.value().at(u) <<
"\n";
321 for (
auto& mapElement : selectionMap) {
322 std::string newPath{path.substr(0, path.find_last_of(
"/") + 1) + mapElement.first +
".mon"};
323 std::ofstream outFile(newPath);
324 if (!outFile.is_open()) {
325 qDebug() <<
"Error opening mon file for writing";
329 outFile << mapElement.first <<
"\n";
330 for (
auto& vectorElement : mapElement.second) {
331 outFile << vectorElement <<
" : " << vectorElement <<
"\n";