Changeset View
Changeset View
Standalone View
Standalone View
src/exportdialog.cpp
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Line(s) | 147 | { | |||
---|---|---|---|---|---|
174 | // close the dialog | 174 | // close the dialog | ||
175 | done(0); | 175 | done(0); | ||
176 | } | 176 | } | ||
177 | 177 | | |||
178 | void ExportDialog::exportToHtml() | 178 | void ExportDialog::exportToHtml() | ||
179 | { | 179 | { | ||
180 | *m_outputStream << HTML_HEADER << "<table>\n"; | 180 | *m_outputStream << HTML_HEADER << "<table>\n"; | ||
181 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | 181 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | ||
182 | ElementListEntry* element_entry = static_cast <ElementListEntry*> (element); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
183 | | ||||
182 | *m_outputStream << "<tr>\n<th colspan=\"2\">" | 184 | *m_outputStream << "<tr>\n<th colspan=\"2\">" | ||
183 | << ((ElementListEntry*)element)->m_element->dataAsString(ChemicalDataObject::name) | 185 | << element_entry->m_element->dataAsString(ChemicalDataObject::name) | ||
you use dynamic_cast when you expect that the cast can fail; since in this case it is assumed it will work, then use static_cast directly instead pino: you use dynamic_cast when you expect that the cast can fail; since in this case it is assumed… | |||||
184 | << "</th>\n</tr>\n"; | 186 | << "</th>\n</tr>\n"; | ||
185 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | 187 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | ||
188 | PropertyListEntry* property_entry = static_cast<PropertyListEntry*> (property); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
189 | | ||||
186 | *m_outputStream << "<tr>\n<td class=\"property\">" | 190 | *m_outputStream << "<tr>\n<td class=\"property\">" | ||
187 | << ((PropertyListEntry*) property)->text() | 191 | << property_entry->text() | ||
ditto also, property is casted more than once within this foreach loop, so factorize it pino: ditto
also, `property` is casted more than once within this foreach loop, so factorize it | |||||
188 | << "</td>\n<td class=\"value\">" | 192 | << "</td>\n<td class=\"value\">" | ||
189 | << KalziumUtils::prettyUnit( | 193 | << KalziumUtils::prettyUnit(element_entry->m_element,property_entry->m_type) | ||
pino: coding style, i.e missing space after comma | |||||
190 | ((ElementListEntry*) element)->m_element, | | |||
191 | ((PropertyListEntry*) property)->m_type) | | |||
192 | << "</td>\n</tr>\n"; | 194 | << "</td>\n</tr>\n"; | ||
pino: ditto | |||||
193 | } | 195 | } | ||
194 | } | 196 | } | ||
195 | *m_outputStream << "</table>\n" << HTML_FOOTER; | 197 | *m_outputStream << "</table>\n" << HTML_FOOTER; | ||
196 | } | 198 | } | ||
197 | 199 | | |||
198 | void ExportDialog::exportToXml() | 200 | void ExportDialog::exportToXml() | ||
199 | { | 201 | { | ||
200 | *m_outputStream << XML_HEADER << "<elements>\n"; | 202 | *m_outputStream << XML_HEADER << "<elements>\n"; | ||
201 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | 203 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | ||
204 | ElementListEntry* element_entry = static_cast<ElementListEntry*> (element); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
205 | | ||||
202 | *m_outputStream << " <element name=\"" | 206 | *m_outputStream << " <element name=\"" | ||
203 | << ((ElementListEntry*) element)->m_element->dataAsString(ChemicalDataObject::name) | 207 | << element_entry->m_element->dataAsString(ChemicalDataObject::name) | ||
pino: ditto | |||||
204 | << "\">\n"; | 208 | << "\">\n"; | ||
205 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | 209 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | ||
210 | PropertyListEntry* property_entry = static_cast<PropertyListEntry*> (property); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
211 | | ||||
206 | *m_outputStream << " <property name=\"" | 212 | *m_outputStream << " <property name=\"" | ||
207 | << ((PropertyListEntry*) property)->text() | 213 | << property_entry->text() | ||
pino: ditto (dynamic_cast + factorize) | |||||
208 | << "\">" | 214 | << "\">" | ||
209 | << KalziumUtils::prettyUnit( | 215 | << KalziumUtils::prettyUnit(element_entry->m_element,property_entry->m_type) | ||
pino: coding style, i.e missing space after comma | |||||
210 | ((ElementListEntry*) element)->m_element, | | |||
211 | ((PropertyListEntry*) property)->m_type) | | |||
212 | << "</property>\n"; | 216 | << "</property>\n"; | ||
pino: ditto | |||||
213 | } | 217 | } | ||
214 | *m_outputStream << " </element>\n"; | 218 | *m_outputStream << " </element>\n"; | ||
215 | } | 219 | } | ||
216 | *m_outputStream << "</elements>\n"; | 220 | *m_outputStream << "</elements>\n"; | ||
217 | } | 221 | } | ||
218 | 222 | | |||
219 | void ExportDialog::exportToCsv() | 223 | void ExportDialog::exportToCsv() | ||
220 | { | 224 | { | ||
221 | *m_outputStream << "Name"; | 225 | *m_outputStream << "Name"; | ||
222 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | 226 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | ||
227 | PropertyListEntry* property_entry = static_cast<PropertyListEntry*> (property); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
228 | | ||||
223 | *m_outputStream << ", \"" | 229 | *m_outputStream << ", \"" | ||
224 | << ((PropertyListEntry*) property)->text() | 230 | << property_entry->text() | ||
pino: ditto | |||||
225 | << "\""; | 231 | << "\""; | ||
226 | } | 232 | } | ||
233 | | ||||
227 | *m_outputStream << "\n"; | 234 | *m_outputStream << "\n"; | ||
228 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | 235 | foreach (QListWidgetItem *element, ui.elementListWidget->selectedItems()) { | ||
236 | ElementListEntry* element_entry = static_cast<ElementListEntry*> (element); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
237 | | ||||
229 | *m_outputStream << "\"" | 238 | *m_outputStream << "\"" | ||
230 | << ((ElementListEntry*) element)->m_element->dataAsString(ChemicalDataObject::name) | 239 | << element_entry->m_element->dataAsString(ChemicalDataObject::name) | ||
pino: ditto (dynamic_cast + factorize) | |||||
231 | << "\""; | 240 | << "\""; | ||
232 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | 241 | foreach (QListWidgetItem *property, ui.propertyListWidget->selectedItems()) { | ||
242 | PropertyListEntry* property_entry = static_cast<PropertyListEntry*> (property); | ||||
pino: coding style, extra space between angle bracket and round bracket | |||||
243 | | ||||
233 | *m_outputStream << ", \"" | 244 | *m_outputStream << ", \"" | ||
234 | << KalziumUtils::prettyUnit( | 245 | << KalziumUtils::prettyUnit(element_entry->m_element,property_entry->m_type) | ||
pino: coding style, i.e missing space after comma | |||||
235 | ((ElementListEntry*) element)->m_element, | | |||
236 | ((PropertyListEntry*) property)->m_type) | | |||
237 | << "\""; | 246 | << "\""; | ||
pino: ditto | |||||
238 | } | 247 | } | ||
239 | *m_outputStream << "\n"; | 248 | *m_outputStream << "\n"; | ||
240 | } | 249 | } | ||
241 | } | 250 | } |
coding style, extra space between angle bracket and round bracket