Commit fb5473e3e9940bef32f2cbfae0bb503b94289219

Authored by bhklein
1 parent 3e581e6c

make inPlace only option, more whitespace fixes

Showing 1 changed file with 37 additions and 42 deletions
openbr/plugins/gallery/csv.cpp
... ... @@ -81,29 +81,29 @@ public:
81 81 for (int i=0; i<headers.size(); i++) {
82 82 CSVHeader header;
83 83 if (headers[i].contains("_")) {
84   - const QStringList subKeys = headers[i].split("_");
85   - header.key = subKeys.first();
86   -
87   - if (processedKeys.contains(header.key))
88   - continue;
89   - else
90   - processedKeys.append(header.key);
91   -
92   - header.subKeys.append(subKeys.last());
93   - header.indices.append(i);
94   -
95   - // Look for other subheaders with the same key
96   - for (int j=i+1; j<headers.size(); j++)
97   - if (headers[j].contains("_")) {
98   - const QStringList subKeys = headers[j].split("_");
99   - if (subKeys.first() == header.key && !header.subKeys.contains(subKeys.last()) /* Check for ill-formed csvs */) {
100   - header.indices.append(j);
101   - header.subKeys.append(subKeys.last());
102   - }
103   - }
  84 + const QStringList subKeys = headers[i].split("_");
  85 + header.key = subKeys.first();
  86 +
  87 + if (processedKeys.contains(header.key))
  88 + continue;
  89 + else
  90 + processedKeys.append(header.key);
  91 +
  92 + header.subKeys.append(subKeys.last());
  93 + header.indices.append(i);
  94 +
  95 + // Look for other subheaders with the same key
  96 + for (int j=i+1; j<headers.size(); j++)
  97 + if (headers[j].contains("_")) {
  98 + const QStringList subKeys = headers[j].split("_");
  99 + if (subKeys.first() == header.key && !header.subKeys.contains(subKeys.last()) /* Check for ill-formed csvs */) {
  100 + header.indices.append(j);
  101 + header.subKeys.append(subKeys.last());
  102 + }
  103 + }
104 104 } else {
105   - header.key = headers[i];
106   - header.indices.append(i);
  105 + header.key = headers[i];
  106 + header.indices.append(i);
107 107 }
108 108 csvHeaders.append(header);
109 109 }
... ... @@ -124,8 +124,6 @@ public:
124 124 class csvGallery : public FileGallery
125 125 {
126 126 Q_OBJECT
127   - Q_PROPERTY(bool inPlace READ get_inPlace WRITE set_inPlace RESET reset_inPlace STORED false)
128   - BR_PROPERTY(bool, inPlace, false)
129 127 Q_PROPERTY(bool combineFiles READ get_combineFiles WRITE set_combineFiles RESET reset_combineFiles STORED false)
130 128 BR_PROPERTY(bool, combineFiles, false)
131 129  
... ... @@ -215,10 +213,10 @@ class csvGallery : public FileGallery
215 213 foreach (const QString &value, QtUtils::parse(f.readLine(), ','))
216 214 values.append(QtUtils::fromString(value));
217 215  
218   - const QString name = values.first().toString();
219   - File &in = combinedFiles[name];
220   - in.name = name;
221   - setValuesFromHeaders(in, headers, values.mid(1));
  216 + const QString name = values.first().toString();
  217 + File &in = combinedFiles[name];
  218 + in.name = name;
  219 + setValuesFromHeaders(in, headers, values.mid(1));
222 220 }
223 221  
224 222 foreach (const File &in, combinedFiles.values())
... ... @@ -235,26 +233,23 @@ class csvGallery : public FileGallery
235 233 in.set("progress", f.pos());
236 234 templates.append(in);
237 235 }
238   - *done = f.atEnd();
  236 + *done = f.atEnd();
239 237 }
240 238 return templates;
241 239 }
242 240  
243 241 void write(const Template &t)
244 242 {
245   - if (inPlace) {
246   - writeOpen();
247   - if (headers.isEmpty()) {
248   - foreach (const QString &key, t.file.localKeys())
249   - headers.append(CSVHeader(key));
250   -
251   - headers.sort();
252   - const QString header = QString(QStringList(QStringList("File") + headers.keys()).join(",") + "\n");
253   - f.write(header.toLocal8Bit());
254   - }
255   - f.write(QString(lineFromFile(t.file) + "\n").toLocal8Bit());
256   - } else
257   - files.append(t.file);
  243 + writeOpen();
  244 + if (headers.isEmpty()) {
  245 + foreach (const QString &key, t.file.localKeys())
  246 + headers.append(CSVHeader(key));
  247 +
  248 + headers.sort();
  249 + const QString header = QString(QStringList(QStringList("File") + headers.keys()).join(",") + "\n");
  250 + f.write(header.toLocal8Bit());
  251 + }
  252 + f.write(QString(lineFromFile(t.file) + "\n").toLocal8Bit());
258 253 }
259 254  
260 255 QString lineFromFile(const br::File file)
... ...