Compare commits

...

8 Commits

Author SHA1 Message Date
0cf8136757 remove include dir 2023-10-24 13:13:07 +03:00
9fee5a7d07 fix Scatter3D::clear 2023-10-24 12:29:55 +03:00
dc5075ad8a add Scatter3D::removeGraphic 2023-10-24 12:15:02 +03:00
876ceec0dc fix Scatter3D graphicMeshSmooth 2023-10-23 20:14:17 +03:00
fa720d4d3d add Scatter3D graphicMeshSmooth 2023-10-23 20:03:43 +03:00
31fd00a97a fix Scatter3D clear() 2023-10-23 19:06:25 +03:00
0e9ca837d1 QAD::Graphic3D 2023-10-23 18:59:16 +03:00
1c857eebff add qad_graphic3d library
scatter3d widget
2023-10-23 18:17:35 +03:00
4 changed files with 267 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ Create imported targets:
* QAD::Blockview
* QAD::Graphic
* QAD::GraphicAnalysis
* QAD::Graphic3D
* QAD::SQLTable
* QAD::TouchWidgets
* QAD::Doc
@@ -45,7 +46,7 @@ if(QAD_FIND_VERSION VERSION_GREATER QAD_VERSION)
message(FATAL_ERROR "QAD version ${QAD_VERSION} is available, but ${QAD_FIND_VERSION} requested!")
endif()
set(__libs "utils;widgets;application;blockview;graphic;graphic_analysis;sql;sql_table;touch_widgets;doc;map")
set(__libs "utils;widgets;application;blockview;graphic;graphic_analysis;graphic3d;sql;sql_table;touch_widgets;doc;map")
if (PIP_FOUND OR BUILDING_PIP)
list(APPEND __libs "piqt;piqt_utils")
endif()
@@ -56,6 +57,7 @@ set(__module_application Application )
set(__module_blockview Blockview )
set(__module_graphic Graphic )
set(__module_graphic_analysis GraphicAnalysis)
set(__module_graphic3d Graphic3D )
set(__module_sql SQL )
set(__module_sql_table SQLTable )
set(__module_touch_widgets TouchWidgets )

View File

@@ -0,0 +1,4 @@
if (HAS_GL)
qad_library(graphic3d "Gui;Widgets;DataVisualization" "")
endif()

View File

@@ -0,0 +1,160 @@
#include "scatter3d.h"
#include <Q3DScatter>
#include <QBoxLayout>
#include <QScatter3DSeries>
#include <QScatterDataArray>
#include <QScatterDataProxy>
Scatter3D::Scatter3D(QWidget * parent): QWidget{parent} {
curGraphic = 0;
canvas = new QtDataVisualization::Q3DScatter();
canvas->setFlag(Qt::FramelessWindowHint);
canvas->axisZ()->setReversed(true);
canvas->setShadowQuality(QtDataVisualization::QAbstract3DGraph::ShadowQualityNone);
container = QWidget::createWindowContainer(canvas);
setLayout(new QVBoxLayout(this));
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(container);
}
Scatter3D::~Scatter3D() {
clear();
canvas->setParent(nullptr);
canvas->deleteLater();
}
QColor Scatter3D::graphicColor(int index) const {
return graphics[index].series->baseColor();
}
float Scatter3D::graphicPointSize(int index) const {
return graphics[index].series->itemSize();
}
Scatter3D::Mesh Scatter3D::graphicMesh(int index) const {
return graphics[index].series->mesh();
}
bool Scatter3D::graphicMeshSmooth(int index) const {
return graphics[index].series->isMeshSmooth();
}
bool Scatter3D::labelAutoRotation() const {
return canvas->axisX()->labelAutoRotation() == 0;
}
void Scatter3D::setCurrentGraphic(int arg) {
if (arg < 0 || arg >= graphics.size()) return;
curGraphic = arg;
}
void Scatter3D::setGraphicsCount(int count) {
if (count < 0) return;
while (graphics.size() < count) {
addGraphic();
}
while (graphics.size() > count) {
auto sg = graphics.takeLast();
canvas->removeSeries(sg.series);
delete sg.series;
}
container->update();
}
void Scatter3D::setGraphicColor(const QColor & color, int index) {
graphics[index].series->setBaseColor(color);
container->update();
}
void Scatter3D::setGraphicPointSize(float sz, int index) {
graphics[index].series->setItemSize(sz);
container->update();
}
void Scatter3D::setGraphicMesh(Mesh mesh, int index) {
graphics[index].series->setMesh(mesh);
container->update();
}
void Scatter3D::setGraphicMeshSmooth(bool smooth, int index) {
graphics[index].series->setMeshSmooth(smooth);
container->update();
}
void Scatter3D::addGraphic(const QColor & color, float pointSize, Mesh mesh, bool meshSmooth) {
Scatter3DGraphic sg;
sg.data = new QtDataVisualization::QScatterDataProxy();
sg.series = new QtDataVisualization::QScatter3DSeries(sg.data);
sg.series->setItemSize(pointSize);
sg.series->setBaseColor(color);
sg.series->setMesh(mesh);
sg.series->setMeshSmooth(meshSmooth);
graphics.append(sg);
canvas->addSeries(sg.series);
container->update();
}
void Scatter3D::removeGraphic(int index) {
if (index < 0 || index >= graphics.size()) return;
canvas->removeSeries(graphics[index].series);
delete graphics[index].series;
graphics.remove(index);
}
void Scatter3D::clear() {
for (auto g: graphics)
g.data->resetArray(nullptr);
}
void Scatter3D::setLabelAutoRotation(bool on) {
if (on) {
canvas->axisX()->setLabelAutoRotation(90);
canvas->axisY()->setLabelAutoRotation(90);
canvas->axisZ()->setLabelAutoRotation(90);
} else {
canvas->axisX()->setLabelAutoRotation(0);
canvas->axisY()->setLabelAutoRotation(0);
canvas->axisZ()->setLabelAutoRotation(0);
}
container->update();
}
void Scatter3D::setGraphicData(const QVector<QVector3D> & points, int index) {
auto arr = new DataArray();
arr->reserve(points.size());
for (const auto & p: points) {
arr->append(p);
}
graphics[index].data->resetArray(arr);
container->update();
}
void Scatter3D::setGraphicData(DataArray * newArray, int index) {
graphics[index].data->resetArray(newArray);
container->update();
}
void Scatter3D::addPoint(const QVector3D & point, int index) {
graphics[index].data->addItem(point);
}

100
libs/graphic3d/scatter3d.h Normal file
View File

@@ -0,0 +1,100 @@
/*
QAD - Qt ADvanced
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCATTER3D_H
#define SCATTER3D_H
#include "qad_graphic3d_export.h"
#include <QAbstract3DSeries>
#include <QWidget>
namespace QtDataVisualization {
class Q3DScatter;
class QScatterDataProxy;
class QScatter3DSeries;
class QScatterDataItem;
} // namespace QtDataVisualization
class QAD_GRAPHIC3D_EXPORT Scatter3D: public QWidget {
Q_OBJECT
using Mesh = QtDataVisualization::QAbstract3DSeries::Mesh;
using DataArray = QVector<QtDataVisualization::QScatterDataItem>;
Q_PROPERTY(int currentGraphic READ currentGraphic WRITE setCurrentGraphic)
Q_PROPERTY(int graphicsCount READ graphicsCount WRITE setGraphicsCount)
Q_PROPERTY(QColor graphicColor READ graphicColor WRITE setGraphicColor)
Q_PROPERTY(float graphicPointSize READ graphicPointSize WRITE setGraphicPointSize)
Q_PROPERTY(Mesh graphicMesh READ graphicMesh WRITE setGraphicMesh)
Q_PROPERTY(bool labelAutoRotation READ labelAutoRotation WRITE setLabelAutoRotation)
Q_PROPERTY(bool graphicMeshSmooth READ graphicMeshSmooth WRITE setGraphicMeshSmooth)
public:
explicit Scatter3D(QWidget * parent = nullptr);
~Scatter3D();
int currentGraphic() const { return curGraphic; }
int graphicsCount() const { return graphics.size(); }
QColor graphicColor() const { return graphicColor(curGraphic); }
QColor graphicColor(int index) const;
float graphicPointSize() const { return graphicPointSize(curGraphic); }
float graphicPointSize(int index) const;
Mesh graphicMesh() const { return graphicMesh(curGraphic); }
Mesh graphicMesh(int index) const;
bool graphicMeshSmooth() const { return graphicMeshSmooth(curGraphic); }
bool graphicMeshSmooth(int index) const;
bool labelAutoRotation() const;
public slots:
void setCurrentGraphic(int arg);
void setGraphicsCount(int count);
void setGraphicColor(const QColor & color, int index);
void setGraphicColor(const QColor & color) { setGraphicColor(color, curGraphic); }
void setGraphicPointSize(float sz, int index);
void setGraphicPointSize(float sz) { setGraphicPointSize(sz, curGraphic); }
void setGraphicMesh(Mesh mesh, int index);
void setGraphicMesh(Mesh mesh) { setGraphicMesh(mesh, curGraphic); }
void setGraphicMeshSmooth(bool smooth, int index);
void setGraphicMeshSmooth(bool smooth) { setGraphicMeshSmooth(smooth, curGraphic); }
void addGraphic(const QColor & color = Qt::darkBlue, float pointSize = 1.f, Mesh mesh = Mesh::MeshSphere, bool meshSmooth = true);
void removeGraphic(int index);
void clear();
void setLabelAutoRotation(bool on);
void setGraphicData(const QVector<QVector3D> & points, int index);
void setGraphicData(const QVector<QVector3D> & points) { setGraphicData(points, curGraphic); }
void setGraphicData(DataArray * newArray, int index);
void setGraphicData(DataArray * newArray) { setGraphicData(newArray, curGraphic); }
void addPoint(const QVector3D & point, int index);
void addPoint(const QVector3D & point) { addPoint(point, curGraphic); }
private:
struct Scatter3DGraphic {
QtDataVisualization::QScatter3DSeries * series;
QtDataVisualization::QScatterDataProxy * data;
};
QWidget * container;
QtDataVisualization::Q3DScatter * canvas;
QVector<Scatter3DGraphic> graphics;
int curGraphic;
};
#endif // SCATTER3D_H