diff --git a/app/elementstablemodel.cpp b/app/elementstablemodel.cpp index 89e4c68689df5a9b729d4bb130d06557d6ee1b62..cbb338f69695aaf55c3509690b251ec9ca8260a5 100644 --- a/app/elementstablemodel.cpp +++ b/app/elementstablemodel.cpp @@ -1,4 +1,4 @@ -#include "elementstablemodel.h" + #include "elementstablemodel.h" #include <QElapsedTimer> ElementsTableModel::ElementsTableModel(QObject *parent) @@ -217,20 +217,27 @@ void ElementsTableModel::update() } -void ElementsTableModel::writeCSV(QFile file) +void ElementsTableModel::writeCSV(QFile & file) { if ( file.open(QIODevice::ReadWrite) ) { QTextStream stream( &file ); stream << "PID , name , status , PPID , user , CPU , memory , uptime" << endl; - foreach (Task t, taskMap) { - stream << t.print(" , ") << endl; - } - //for (QMap<int, Task>::const_iterator it = taskMap.cbegin() ; taskMap.cend() ; ++it) - //{ - // stream << it.print(" , ") << endl; - //} + + //qDebug() << taskMap.find(1)->getPID() << endl; + +// foreach (Task t, taskMap) { +// qDebug() << "test" << endl ; +// //stream << t.print(";") << endl; +// } + + /* + for (QMap<int, Task>::iterator it = taskMap.begin() ; it != taskMap.end() ; ++it) + { + stream << "test" << endl ;; + } + */ } } diff --git a/app/elementstablemodel.h b/app/elementstablemodel.h index 363829720e73ec694c0e234db87f2cbc1e97f316..e493f52a848210a9d7210bf8c56149ff6b727565 100644 --- a/app/elementstablemodel.h +++ b/app/elementstablemodel.h @@ -44,7 +44,7 @@ public: bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; - void writeCSV(QFile file); + void writeCSV(QFile & file); private: diff --git a/app/main.cpp b/app/main.cpp index f30c28df1a7ad1e5e97df2762181ec35fc3f9c64..534bc8428b2cb31b89cebf83f87cec0d413c073c 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -11,7 +11,8 @@ int main(int argc, char *argv[]) w.show(); // lance le controller qui gère le timer pour l'update régulier - Controller * _controller = new Controller(&w); + Controller * controller = new Controller(&w); + return a.exec(); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 81e440d8041b7a87aa5508adfd92c8e15b576346..e58d9a14ff99dc69cc87c3b10ba50663ec857cf3 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -73,3 +73,16 @@ void MainWindow::on_commandLinkButton_7_clicked() if (ok && !text.isEmpty()) system(text.toStdString().c_str()); } + + +void MainWindow::on_actionExport_actual_state_triggered() +{ + QString fileName = QFileDialog::getSaveFileName( + this, tr("Export as..."), "", tr("Fichiers csv (*.csv)")); + + if (!fileName.isEmpty()) + { + QFile file(fileName); + model->writeCSV(file); + } +} diff --git a/app/mainwindow.h b/app/mainwindow.h index 905daf3f08838e964ce4d82ba7512369f44c3c73..530179a2121d5b43aae5015c74ab549437fb3967 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -8,6 +8,7 @@ #include "generalstatus.h" #include "elementstablemodel.h" #include "elementslistmodel.h" +#include <QFileDialog> namespace Ui { class MainWindow; @@ -23,10 +24,13 @@ public: void update_status(GeneralStatus &genStatus); void set_task(ElementsTableModel * eltCollection); void update_tasks(); + ElementsTableModel * model; private slots: void on_commandLinkButton_7_clicked(); + void on_actionExport_actual_state_triggered(); + private: Ui::MainWindow *ui; }; diff --git a/app/mainwindow.ui b/app/mainwindow.ui index 500baf70befe911ebaeab23a6d88d5f8d646e110..5fd407a57c6db4c65db1e0a2e1e1be9729583991 100644 --- a/app/mainwindow.ui +++ b/app/mainwindow.ui @@ -320,6 +320,7 @@ <property name="title"> <string>File</string> </property> + <addaction name="actionExport_actual_state"/> <addaction name="actionAbout"/> <addaction name="actionQuit"/> </widget> @@ -381,6 +382,11 @@ <string>Create task</string> </property> </action> + <action name="actionExport_actual_state"> + <property name="text"> + <string>Export actual state</string> + </property> + </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources/>