Merge pull request #2235 from maxGimeno/Make_the_statistics_exportable-GF

Polyhedron_demo: make the statistics exportable
This commit is contained in:
Laurent Rineau 2017-09-04 15:20:55 +02:00
commit 25367b9141
3 changed files with 97 additions and 16 deletions

View File

@ -1854,6 +1854,8 @@ void MainWindow::statisticsOnItem()
statistics_dlg, SLOT(accept()));
connect(statistics_ui->updateButton, SIGNAL(clicked()),
this, SLOT(statisticsOnItem()));
connect(statistics_ui->exportButton, &QPushButton::clicked,
this, &MainWindow::exportStatistics);
}
statistics_ui->label_htmltab->setText(get_item_stats());
@ -2032,3 +2034,53 @@ void MainWindow::set_facegraph_mode_adapter(bool is_polyhedron)
set_face_graph_default_type(SURFACE_MESH);
}
void MainWindow::exportStatistics()
{
std::vector<Scene_item*> items;
Q_FOREACH(int id, getSelectedSceneItemIndices())
{
Scene_item* s_item = scene->item(id);
items.push_back(s_item);
}
QString str;
Q_FOREACH(Scene_item* sit, items)
{
CGAL::Three::Scene_item::Header_data data = sit->header();
if(data.titles.size()>0)
{
int titles_limit =0;
int title = 0;
str.append(QString("%1: \n").arg(sit->name()));
for(int j=0; j<data.categories.size(); j++)
{
str.append(QString(" %1: \n")
.arg(data.categories[j].first));
titles_limit+=data.categories[j].second;
for(;title<titles_limit; ++title)
{
str.append(QString(" %1: ").arg(data.titles.at(title)));
str.append(QString("%1\n").arg(sit->computeStats(title)));
title++;
}
}
}
}
QString filename =
QFileDialog::getSaveFileName((QWidget*)sender(),
"",
QString("Statistics.txt"),
"Text Files (*.txt)");
if(filename.isEmpty())
return;
QFile output(filename);
output.open(QIODevice::WriteOnly | QIODevice::Text);
if(!output.isOpen()){
qDebug() << "- Error, unable to open" << "outputFilename" << "for output";
}
QTextStream outStream(&output);
outStream << str;
output.close();
}

View File

@ -240,6 +240,11 @@ public Q_SLOTS:
* set_face_graph_default_type sets the global state of the application to `Polyhedron mode` or `Surface_mesh mode`.
*/
void set_face_graph_default_type(MainWindow::Face_graph_mode m);
/*!
* Writes the statistics dialog content in a text file.
*/
void exportStatistics();
protected Q_SLOTS:
//!Gets the new selected item(s) from the Geometric Objects view and updates the scene

View File

@ -25,22 +25,8 @@
<property name="modal">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<widget class="QDialogButtonBox" name="okButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0" alignment="Qt::AlignRight">
<widget class="QToolButton" name="updateButton">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0,0">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="label_htmltab">
@ -63,6 +49,44 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0">
<item>
<widget class="QPushButton" name="exportButton">
<property name="text">
<string>&amp;Export...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="updateButton">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="okButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>