[qet] [3348] Nomenclature, some improvement |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3348
Author: blacksun
Date: 2014-10-05 15:35:01 +0200 (Sun, 05 Oct 2014)
Log Message:
-----------
Nomenclature, some improvement
Modified Paths:
--------------
trunk/sources/nomenclature.cpp
trunk/sources/nomenclature.h
trunk/sources/qetdiagrameditor.cpp
Modified: trunk/sources/nomenclature.cpp
===================================================================
--- trunk/sources/nomenclature.cpp 2014-10-05 13:08:24 UTC (rev 3347)
+++ trunk/sources/nomenclature.cpp 2014-10-05 13:35:01 UTC (rev 3348)
@@ -18,6 +18,7 @@
#include <QtDebug>
#include "nomenclature.h"
+#include "elementprovider.h"
#define PR(x) qDebug() << #x " = " << x;
/**
@@ -29,10 +30,8 @@
m_project(project)
{
m_parent = parent;
- if(!m_project->isEmpty()){
- //get list of schema present in project
- m_list_diagram = m_project -> diagrams();
- }
+ //get list of schema present in project
+ m_list_diagram = m_project -> diagrams();
}
/**
@@ -46,21 +45,11 @@
@param true if success
*/
bool nomenclature::saveToCSVFile() {
- if(m_list_diagram.isEmpty()) return false;
-
- //Process...
- QString data = tr("NOMENCLATURE : ") + m_project -> title() + "\n\n";
- data += tr("Folio") +";"+ tr("Sch\351ma") +";"+ tr("D\351signation")+";"+ tr("Label") +";"+ tr("Commententaire") +";"+ tr("Fabriquant") +";"+ tr("Reference") +";"+ tr("Machine-reference\n");
- QStringList rows;
- for(int i=0; i<m_list_diagram.count(); i++){
- rows = getRows(m_list_diagram.at(i));
- for(int j=0;j<rows.count();j++){
- data += rows.at(j);
- }
- }
-
// SAVE IN FILE
QString name = tr("nomenclature_") + QString(m_project -> title());
+ if (!name.endsWith(".csv")) {
+ name += ".csv";
+ }
QString filename = QFileDialog::getSaveFileName(this->m_parent, tr("Enregister sous... "), name, tr("Fichiers csv (*.csv)"));
QFile file(filename);
if( !filename.isEmpty() ) {
@@ -75,7 +64,7 @@
}
if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream stream(&file);
- stream << data << endl;
+ stream << getNomenclature() << endl;
}
else return false;
}
@@ -85,27 +74,51 @@
}
/**
- gets rows of nomenclature
- @return the list of rows
-*/
-QStringList nomenclature::getRows(Diagram *schema) {
- QString row;
- QStringList list;
- QList<Element *> elements_list;
+ * @brief nomenclature::getNomenclature
+ * Create and formated a nomenclature to csv file.
+ * @return The QString of nomenclature
+ */
+QString nomenclature::getNomenclature() {
+ //Process...
+ QString data = tr("NOMENCLATURE : ") + m_project -> title() + "\n\n";
+ data += tr("Folio") +";"+ tr("Sch\351ma") +";"+ tr("D\351signation")+";"+ tr("Label") +";"+ tr("Commententaire") +";"+ tr("Fabriquant") +";"+ tr("Reference") +";"+ tr("Machine-reference\n");
- //elements_list = schema->customElements();
- elements_list = schema->content().elements.toList();
- for(int j=0;j<elements_list.count();j++){
- row += QString::number(schema->folioIndex()+1) + ";";
- row += schema->title() + ";";
- row += elements_list.at(j)->name() + ";";
- row += elements_list.at(j)->elementInformations()["label"].toString() + ";";
- row += elements_list.at(j)->elementInformations()["comment"].toString() + ";";
- row += elements_list.at(j)->elementInformations()["manufacturer"].toString() + ";";
- row += elements_list.at(j)->elementInformations()["manufacturer-reference"].toString() + ";";
- row += elements_list.at(j)->elementInformations()["machine-manufacturer-reference"].toString() + "\n";
- list << row;
+ if(m_list_diagram.isEmpty()) return data;
+
+ foreach (Diagram *d, m_list_diagram) {
+ //Get only simple, master and unlinked slave element.
+ ElementProvider ep(d);
+ QList <Element *> list_elements;
+ list_elements << ep.find(Element::Simple | Element::Master);
+ list_elements << ep.freeElement(Element::Slave);
+
+ foreach (Element *elmt, list_elements) {
+ data += getElementInfo(elmt);
+ }
}
- return list;
+
+ return data;
}
+/**
+ * @brief nomenclature::getElementInfo
+ * @param elmt : the element to getinfo
+ * @return : QString with information about element formated to csv file
+ */
+QString nomenclature::getElementInfo(const Element *elmt) {
+ QString info;
+
+ Diagram *diagram = elmt -> diagram();
+ DiagramContext elmt_info = elmt -> elementInformations();
+
+ info += QString::number(diagram -> folioIndex()+1) + ";";
+ info += diagram -> title() + ";";
+ info += elmt -> name() + ";";
+ info += elmt_info["label"].toString() + ";";
+ info += elmt_info["comment"].toString() + ";";
+ info += elmt_info["manufacturer"].toString() + ";";
+ info += elmt_info["manufacturer-reference"].toString() + ";";
+ info += elmt_info["machine-manufacturer-reference"].toString() + "\n";
+
+ return info;
+}
Modified: trunk/sources/nomenclature.h
===================================================================
--- trunk/sources/nomenclature.h 2014-10-05 13:08:24 UTC (rev 3347)
+++ trunk/sources/nomenclature.h 2014-10-05 13:35:01 UTC (rev 3348)
@@ -45,7 +45,7 @@
// constructors, destructor
public:
- nomenclature(QETProject *project =0, QWidget *parent =0);
+ nomenclature(QETProject *project, QWidget *parent =0);
virtual ~nomenclature();
// attributes
@@ -57,7 +57,8 @@
private:
- QStringList getRows(Diagram *schema);
+ QString getNomenclature ();
+ QString getElementInfo (const Element *elmt);
};
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2014-10-05 13:08:24 UTC (rev 3347)
+++ trunk/sources/qetdiagrameditor.cpp 2014-10-05 13:35:01 UTC (rev 3348)
@@ -1806,10 +1806,8 @@
*/
void QETDiagramEditor::nomenclatureProject() {
//TODO: Test nomenclature CYRIL F.
- nomenclature *nomencl= new nomenclature(currentProject()->project() ,this);
- nomencl->saveToCSVFile();
-
- delete nomencl;
+ nomenclature nomencl(currentProject()->project() ,this);
+ nomencl.saveToCSVFile();
}
/**