progress bar, code cleaning, popup menu for closing tabs

This commit is contained in:
Paul Leroy
2025-03-04 16:31:58 +01:00
parent 1c3e619fe5
commit 6a1982a0a0
9 changed files with 109 additions and 44 deletions
+11 -4
View File
@@ -3,7 +3,7 @@
#include <QWidget>
#include <qcustomplot.h>.h>
#include <qcustomplot.h>
namespace Ui {
class AnglesCustomPlot;
@@ -11,7 +11,7 @@ class AnglesCustomPlot;
class AnglesCustomPlot : public QCustomPlot
{
Q_OBJECT
public:
explicit AnglesCustomPlot(const QVector<double>& data, const QString& xLabel, int nbBins,
QWidget *parent = nullptr);
@@ -23,10 +23,17 @@ public:
void rescale();
void mouseDoubleClickEvent(QMouseEvent *event) override;
QSharedPointer<QCPBarsDataContainer> dataContainer(){return m_bars->data();}
void emitCloseTab(){emit closeTab();}
void mouseDoubleClickEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
signals:
void closeTab();
private:
Ui::AnglesCustomPlot *ui;
+5 -1
View File
@@ -113,8 +113,12 @@ private:
static std::shared_ptr<G3PointAction> s_g3PointAction;
static std::shared_ptr<G3PointPlots> s_g3PointPlots;
static QPointer<G3PointPlots> s_g3PointPlots;
GrainsAsEllipsoids* m_grainsAsEllipsoids;
std::unique_ptr<QProgressBar> m_progress;
int m_currentNumberOfSteps;
};
}
+2
View File
@@ -21,6 +21,8 @@ public:
void addToTabWidget(QWidget* widget);
void closeCurrentWidget();
template<typename SharedDataContainer>
bool exportToCSV(QString filename, SharedDataContainer container) const;
+9 -1
View File
@@ -64,8 +64,9 @@ protected:
};
class WolmanCustomPlot : public QWidget
class WolmanCustomPlot : public QCustomPlot
{
Q_OBJECT
public:
WolmanCustomPlot(const Eigen::ArrayXf& d_sample);
@@ -73,6 +74,13 @@ public:
QCPGraph* m_graph;
void emitCloseTab(){emit closeTab();}
void mousePressEvent(QMouseEvent* event) override;
signals:
void closeTab();
private:
Ui::WolmanCustomPlot *ui;
};
+13
View File
@@ -129,3 +129,16 @@ void AnglesCustomPlot::mouseDoubleClickEvent(QMouseEvent *event)
}
QCustomPlot::mouseDoubleClickEvent(event);
}
void AnglesCustomPlot::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton)
{
QMenu* menu = new QMenu(this);
QAction* action = new QAction("Close tab");
menu->addAction(action);
connect(action, &QAction::triggered, this, &AnglesCustomPlot::emitCloseTab);
menu->popup(event->globalPos());
}
QCustomPlot::mousePressEvent(event);
}
+38 -21
View File
@@ -49,11 +49,12 @@ namespace G3Point
{
std::shared_ptr<G3PointAction> G3PointAction::s_g3PointAction;
std::shared_ptr<G3PointPlots> G3PointAction::s_g3PointPlots;
QPointer<G3PointPlots> G3PointAction::s_g3PointPlots;
G3PointAction::G3PointAction(ccPointCloud *cloud, ccMainAppInterface *app)
: m_app(app)
, m_dlg(nullptr)
, m_grainsAsEllipsoids(nullptr)
{
assert(cloud);
setCloud(cloud);
@@ -76,7 +77,7 @@ void G3PointAction::GetG3PointAction(ccPointCloud *cloud, ccMainAppInterface *ap
if (!G3PointDisclaimer::show(app))
return;
s_g3PointPlots.reset(new G3PointPlots(cloud->getName()));
s_g3PointPlots = new G3PointPlots(cloud->getName());
if (!s_g3PointAction) // create the singleton if needed
{
@@ -99,7 +100,7 @@ void G3PointAction::GetG3PointAction(ccPointCloud *cloud, ccMainAppInterface *ap
s_g3PointAction->showDlg();
}
RGBAColorsTableType getRandomColors(int randomColorsNumber)
RGBAColorsTableType getRandomColors(size_t randomColorsNumber)
{
Q_ASSERT(randomColorsNumber > 1);
@@ -532,12 +533,13 @@ bool G3PointAction::updateLabelsAndColors()
return false;
}
for (int index = 0; index < m_cloud->size(); index++) // points which are not in the stacks will have the label -1
for (unsigned index = 0; index < m_cloud->size(); index++) // points which are not in the stacks will have the label -1
{
g3point_label->setValue(index, -1);
m_labels = -1;
}
m_labels = -1;
for (int k = 0; k < m_stacks.size(); k++)
{
const std::vector<int>& stack = m_stacks[k];
@@ -1103,7 +1105,7 @@ void G3PointAction::showWolman(const Eigen::ArrayXf& d_sample)
{
// QCustomPlot
if (!s_g3PointPlots)
s_g3PointPlots.reset(new G3PointPlots(m_cloud->getName()));
s_g3PointPlots = new G3PointPlots(m_cloud->getName());
s_g3PointPlots->addToTabWidget(new WolmanCustomPlot(d_sample));
s_g3PointPlots->show();
}
@@ -1300,7 +1302,7 @@ bool G3PointAction::angles()
// QCustomPlot
if (!s_g3PointPlots)
s_g3PointPlots.reset(new G3PointPlots(m_cloud->getName()));
s_g3PointPlots = new G3PointPlots(m_cloud->getName());
int nbBins = m_dlg->getAnglesNbBins();
s_g3PointPlots->addToTabWidget(new AnglesCustomPlot(granuloAngleMView, "Azimut", nbBins));
s_g3PointPlots->addToTabWidget(new AnglesCustomPlot(granuloAngleXView, "Dip", nbBins));
@@ -2008,42 +2010,57 @@ bool G3PointAction::setCloud(ccPointCloud *cloud)
CCCoreLib::ScalarField* g3PointLabelBackupSF = m_cloud->getScalarField(sfIdxBackup);
// get the set of labels
std::set<int> labels;
std::set<ScalarType> labelsSet;
for (unsigned int index = 0; index < m_cloud->size(); index++)
{
labels.insert(g3PointLabelSF->getValue(index));
labelsSet.insert(g3PointLabelSF->getValue(index));
}
// remove -1 from the set
labelsSet.erase(-1);
// build a map to handle cases were g3point_label is not a regular range with step 1
// keys = labels
// values = index
std::map<ScalarType, int> labelsMap;
int index = 0;
for (auto label : labelsSet)
{
labelsMap[label] = index;
index++;
}
// build stacks from g3point_index
std::map<ScalarType, std::vector<int>> labelStackMap;
int nPointsInGrains = 0;
m_progress.reset(new QProgressBar());
m_progress->setRange(0, m_cloud->size());
m_progress->setWindowTitle("Processing g3point_label");
m_progress->show();
std::vector<std::vector<int>> newStacks(labelsSet.size());
for (unsigned int index = 0; index < m_cloud->size(); index++)
{
ScalarType label = g3PointLabelSF->getValue(index);
g3PointLabelBackupSF->setValue(index, label); // save the originale G3Point label
if (label != -1) // -1 is a generic index corresponding to all points which do not belong to valid grains
{
labelStackMap[label].push_back(index);
newStacks[labelsMap[label]].push_back(index);
nPointsInGrains++;
}
if (index % 20 == 0)
{
m_progress->setValue(index);
QApplication::processEvents();
}
}
// initialize m_stacks
std::vector<std::vector<int>> newStacks;
for (const auto& item : labelStackMap)
{
newStacks.push_back(item.second);
}
m_progress->hide();
QApplication::processEvents();
ccLog::Print("[G3PointAction::setCloud] g3point_label available, found "
+ QString::number(nPointsInGrains) + "/" + QString::number(cloud->size())
+ " points belonging to " + QString::number(newStacks.size()) + " grains");
std::cout << "[d] processNewStacks" << std::endl;
processNewStacks(newStacks, nPointsInGrains);
std::cout << "[e]" << std::endl;
}
return true;
+14
View File
@@ -55,6 +55,20 @@ void G3PointPlots::addToTabWidget(QWidget* widget)
{
this->ui->tabWidget->addTab(widget, widget->windowTitle());
this->ui->tabWidget->setCurrentWidget(widget);
if (widget->property("TypeOfCustomPlot").toString() == "AnglesCustomPlot")
{
connect(static_cast<AnglesCustomPlot*>(widget), &AnglesCustomPlot::closeTab, this, &G3PointPlots::closeCurrentWidget);
}
else if (widget->property("TypeOfCustomPlot").toString() == "WolmanCustomPlot")
{
connect(static_cast<WolmanCustomPlot*>(widget), &WolmanCustomPlot::closeTab, this, &G3PointPlots::closeCurrentWidget);
}
}
void G3PointPlots::closeCurrentWidget()
{
this->ui->tabWidget->currentWidget()->deleteLater();
}
template<typename SharedDataContainer>
+17 -4
View File
@@ -10,7 +10,7 @@ WolmanCustomPlot::WolmanCustomPlot(const Eigen::ArrayXf &d_sample):
setWindowTitle("Wolman");
m_graph = this->ui->customPlot->addGraph();
m_graph = this->addGraph();
QVector<double> x_data(d_sample.size());
QVector<double> y_data(d_sample.size());
for (int k = 0; k < d_sample.size(); k++)
@@ -22,7 +22,20 @@ WolmanCustomPlot::WolmanCustomPlot(const Eigen::ArrayXf &d_sample):
m_graph->setData(x_data, y_data);
m_graph->rescaleAxes();
// give the axes some labels:
this->ui->customPlot->xAxis->setScaleType(QCPAxis::stLogarithmic);
this->ui->customPlot->xAxis->setLabel("Diameter [mm]");
this->ui->customPlot->yAxis->setLabel("CDF");
this->xAxis->setScaleType(QCPAxis::stLogarithmic);
this->xAxis->setLabel("Diameter [mm]");
this->yAxis->setLabel("CDF");
}
void WolmanCustomPlot::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton)
{
QMenu* menu = new QMenu(this);
QAction* action = new QAction("Close tab");
menu->addAction(action);
connect(action, &QAction::triggered, this, &WolmanCustomPlot::emitCloseTab);
menu->popup(event->globalPos());
}
QCustomPlot::mousePressEvent(event);
}
-13
View File
@@ -13,20 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="1">
<item row="0" column="0" colspan="2">
<widget class="QCustomPlot" name="customPlot" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QCustomPlot</class>
<extends>QWidget</extends>
<header>qcustomplot.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>