MNE-CPP  beta 1.0
selectionloader.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "selectionloader.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace UTILSLIB;
51 
52 
53 //*************************************************************************************************************
54 //=============================================================================================================
55 // DEFINE MEMBER METHODS
56 //=============================================================================================================
57 
59 {
60 }
61 
62 
63 //*************************************************************************************************************
64 
65 bool SelectionLoader::readMNESelFile(QString path, QMap<QString,QStringList> &selectionMap)
66 {
67  //Open .sel file
68  if(!path.contains(".sel"))
69  return false;
70 
71  //clear the map first
72  selectionMap.clear();
73 
74  QFile file(path);
75  if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
76  qDebug()<<"Error opening selection file";
77  return false;
78  }
79 
80  //Start reading from file
81  QTextStream in(&file);
82 
83  while(!in.atEnd()) {
84  QString line = in.readLine();
85 
86  if(line.contains("%") == false && line.contains(":") == true) //Skip commented areas in file
87  {
88  QStringList firstSplit = line.split(":");
89 
90  //Create new key
91  QString key = firstSplit.at(0);
92 
93  QStringList secondSplit = firstSplit.at(1).split("|");
94 
95  //Delete last element if it is a blank character
96  if(secondSplit.at(secondSplit.size()-1) == "")
97  secondSplit.removeLast();
98 
99  //Add to map
100  selectionMap.insert(key, secondSplit);
101  }
102  }
103 
104  file.close();
105 
106  return true;
107 }
SelectionLoader class declaration.
bool readMNESelFile(QString path, QMap< QString, QStringList > &selectionMap)