graphic fix
This commit is contained in:
@@ -186,6 +186,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
|||||||
text_color = palette().color(QPalette::WindowText);
|
text_color = palette().color(QPalette::WindowText);
|
||||||
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
||||||
graphics.append(GraphicType());
|
graphics.append(GraphicType());
|
||||||
|
graphics.back().init();
|
||||||
curGraphic = 0;
|
curGraphic = 0;
|
||||||
selpen = palette().color(QPalette::WindowText);
|
selpen = palette().color(QPalette::WindowText);
|
||||||
selpen.setStyle(Qt::DashLine);
|
selpen.setStyle(Qt::DashLine);
|
||||||
@@ -207,6 +208,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
|||||||
|
|
||||||
|
|
||||||
Graphic::~Graphic() {
|
Graphic::~Graphic() {
|
||||||
|
for (auto & g: graphics)
|
||||||
|
g.destroy();
|
||||||
#ifdef NO_BUTTONS
|
#ifdef NO_BUTTONS
|
||||||
delete buttons_menu;
|
delete buttons_menu;
|
||||||
#endif
|
#endif
|
||||||
@@ -1260,6 +1263,7 @@ void Graphic::setCurrentGraphic(int arg) {
|
|||||||
|
|
||||||
void Graphic::setGraphicsCount(int count, bool update) {
|
void Graphic::setGraphicsCount(int count, bool update) {
|
||||||
if (count < 0) return;
|
if (count < 0) return;
|
||||||
|
bool changed = false;
|
||||||
while (graphics.size() < count) {
|
while (graphics.size() < count) {
|
||||||
GraphicType gt(tr("y(x)"));
|
GraphicType gt(tr("y(x)"));
|
||||||
if (loaded_configs.size() > graphics.size())
|
if (loaded_configs.size() > graphics.size())
|
||||||
@@ -1267,12 +1271,14 @@ void Graphic::setGraphicsCount(int count, bool update) {
|
|||||||
else
|
else
|
||||||
gt.pen.setColor(QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - _G_QRAND_ % 115));
|
gt.pen.setColor(QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - _G_QRAND_ % 115));
|
||||||
graphics.append(gt);
|
graphics.append(gt);
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
while (graphics.size() > count) {
|
while (graphics.size() > count) {
|
||||||
delete graphics.back().pb;
|
graphics.back().destroy();
|
||||||
graphics.pop_back();
|
graphics.pop_back();
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
if (update) updateLegend();
|
if (update && changed) updateLegend();
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef _G_QRAND_
|
#undef _G_QRAND_
|
||||||
@@ -1280,7 +1286,7 @@ void Graphic::setGraphicsCount(int count, bool update) {
|
|||||||
|
|
||||||
void Graphic::removeGraphic(int arg, bool update) {
|
void Graphic::removeGraphic(int arg, bool update) {
|
||||||
if (arg < 0 || arg >= graphics.size()) return;
|
if (arg < 0 || arg >= graphics.size()) return;
|
||||||
delete graphics[arg].pb;
|
graphics[arg].destroy();
|
||||||
graphics.remove(arg);
|
graphics.remove(arg);
|
||||||
if (update) updateLegend();
|
if (update) updateLegend();
|
||||||
}
|
}
|
||||||
@@ -2418,24 +2424,24 @@ void Graphic::updateLegend(bool es) {
|
|||||||
QLayoutItem * li = ui->layoutLegend->itemAtPosition(r, c);
|
QLayoutItem * li = ui->layoutLegend->itemAtPosition(r, c);
|
||||||
if (!li) continue;
|
if (!li) continue;
|
||||||
if (!li->widget()) continue;
|
if (!li->widget()) continue;
|
||||||
while (li->widget()->actions().isEmpty())
|
ui->layoutLegend->removeWidget(li->widget());
|
||||||
li->widget()->removeAction(li->widget()->actions()[0]);
|
|
||||||
delete li->widget();
|
|
||||||
}
|
}
|
||||||
ui->layoutLegend->invalidate();
|
ui->layoutLegend->invalidate();
|
||||||
for (int i = 0; i < graphics.size(); i++) {
|
for (int i = 0; i < graphics.size(); i++) {
|
||||||
graphics[i].pb = new QCheckBox(graphics[i].name);
|
if (graphics[i].init()) {
|
||||||
|
QAction * act = new QAction(tr("Check all"), 0);
|
||||||
|
act->setCheckable(true);
|
||||||
|
act->setChecked(true);
|
||||||
|
graphics[i].pb->addAction(act);
|
||||||
|
connect(act, SIGNAL(triggered(bool)), this, SLOT(graphicAllVisibleChange(bool)));
|
||||||
|
connect(graphics[i].pb, SIGNAL(toggled(bool)), this, SLOT(graphicVisibleChange(bool)));
|
||||||
|
graphics[i].pb->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
|
}
|
||||||
graphics[i].pb->setIconSize(pix.size());
|
graphics[i].pb->setIconSize(pix.size());
|
||||||
graphics[i].pb->setIcon(graphics[i].icon);
|
graphics[i].pb->setIcon(graphics[i].icon);
|
||||||
graphics[i].pb->setChecked(graphics[i].visible);
|
graphics[i].pb->setChecked(graphics[i].visible);
|
||||||
|
graphics[i].pb->setText(graphics[i].name);
|
||||||
graphics[i].pb->setProperty("graphic_num", i);
|
graphics[i].pb->setProperty("graphic_num", i);
|
||||||
graphics[i].pb->setContextMenuPolicy(Qt::ActionsContextMenu);
|
|
||||||
QAction * act = new QAction(tr("Check all"), 0);
|
|
||||||
act->setCheckable(true);
|
|
||||||
act->setChecked(true);
|
|
||||||
graphics[i].pb->addAction(act);
|
|
||||||
connect(act, SIGNAL(triggered(bool)), this, SLOT(graphicAllVisibleChange(bool)));
|
|
||||||
connect(graphics[i].pb, SIGNAL(toggled(bool)), this, SLOT(graphicVisibleChange(bool)));
|
|
||||||
int cps = graphics[i].pb->sizeHint().width() + 4;
|
int cps = graphics[i].pb->sizeHint().width() + 4;
|
||||||
if (cps > ps) ps = cps;
|
if (cps > ps) ps = cps;
|
||||||
}
|
}
|
||||||
@@ -2446,8 +2452,7 @@ void Graphic::updateLegend(bool es) {
|
|||||||
ui->scrollLegend->hide();
|
ui->scrollLegend->hide();
|
||||||
for (int i = 0; i < graphics.size(); i++) {
|
for (int i = 0; i < graphics.size(); i++) {
|
||||||
ui->layoutLegend->addWidget(graphics[i].pb, row, col);
|
ui->layoutLegend->addWidget(graphics[i].pb, row, col);
|
||||||
QCheckBox * check = graphics[i].pb;
|
graphics[i].pb->show();
|
||||||
check->show();
|
|
||||||
if (leg_sa->minimum_hei == 0) {
|
if (leg_sa->minimum_hei == 0) {
|
||||||
leg_sa->minimum_hei = ui->widgetLegend->sizeHint().height();
|
leg_sa->minimum_hei = ui->widgetLegend->sizeHint().height();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ GraphicType::GraphicType(QString name_, QColor color, Qt::PenStyle style, double
|
|||||||
name = name_;
|
name = name_;
|
||||||
visible = visible_;
|
visible = visible_;
|
||||||
pointWidth = 2.;
|
pointWidth = 2.;
|
||||||
pb = new QCheckBox(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +33,20 @@ void GraphicType::removeData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GraphicType::init() {
|
||||||
|
if (pb) return false;
|
||||||
|
pb = new QCheckBox(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicType::destroy() {
|
||||||
|
if (!pb) return;
|
||||||
|
delete pb;
|
||||||
|
pb = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// GraphicConf
|
// GraphicConf
|
||||||
|
|
||||||
GraphicConf::GraphicConf(QVector<GraphicType> & graphics_, QWidget * parent): QDialog(parent), graphics(graphics_) {
|
GraphicConf::GraphicConf(QVector<GraphicType> & graphics_, QWidget * parent): QDialog(parent), graphics(graphics_) {
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ struct QAD_GRAPHIC_EXPORT GraphicType {
|
|||||||
double width = 0.,
|
double width = 0.,
|
||||||
bool visible_ = true);
|
bool visible_ = true);
|
||||||
void removeData();
|
void removeData();
|
||||||
|
bool init();
|
||||||
|
void destroy();
|
||||||
//~GraphicType() {delete pb;}
|
//~GraphicType() {delete pb;}
|
||||||
QString name;
|
QString name;
|
||||||
QPolygonF polyline;
|
QPolygonF polyline;
|
||||||
@@ -54,7 +56,7 @@ struct QAD_GRAPHIC_EXPORT GraphicType {
|
|||||||
double pointWidth;
|
double pointWidth;
|
||||||
double max_x;
|
double max_x;
|
||||||
double max_x_pause;
|
double max_x_pause;
|
||||||
QCheckBox * pb;
|
QCheckBox * pb = nullptr;
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
bool visible;
|
bool visible;
|
||||||
QRectF cvrect;
|
QRectF cvrect;
|
||||||
|
|||||||
Reference in New Issue
Block a user