GraphViewSettingItem.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "pch.h"
  2. #include "GraphViewSettingItem.h"
  3. #include <QColorDialog>
  4. GraphViewSettingItem::GraphViewSettingItem(GraphPlott* view, GraphPlottSeries* series, QWidget *parent) : QWidget(parent), series(series), view(view), colorButton(new ColorButton(this, series->color))
  5. {
  6. ui.setupUi(this);
  7. // Init
  8. switch (series->type) {
  9. case GraphPlottSeries::SeriesType::Dot:
  10. ui.SytleComboBox->setCurrentIndex(1);
  11. break;
  12. case GraphPlottSeries::SeriesType::LineDot:
  13. ui.SytleComboBox->setCurrentIndex(2);
  14. break;
  15. case GraphPlottSeries::SeriesType::Line:
  16. default:
  17. ui.SytleComboBox->setCurrentIndex(0);
  18. break;
  19. }
  20. ui.LineSlider->setValue(series->lineWidth);
  21. ui.CircleSlider->setValue(series->circleRadius);
  22. dissableSlidersOnType();
  23. updateGroupBoxTitle();
  24. ui.RightFormLayout->setWidget(1, QFormLayout::FieldRole, colorButton);
  25. //Connect
  26. connect(ui.LineSlider, &QSlider::valueChanged, [=](const int& newValue) { series->lineWidth = newValue; view->update(); });
  27. connect(ui.CircleSlider, &QSlider::valueChanged, [=](const int& newValue) { series->circleRadius = newValue; view->update(); });
  28. connect(ui.SytleComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](const int& newValue) { setType(newValue);dissableSlidersOnType();view->update(); });
  29. connect(ui.HideCheckbox, &QCheckBox::stateChanged, [=](const int& newValue) { series->hide = (newValue==2); view->update(); });
  30. //connect(ui.SetColorButton, &QPushButton::pressed, this, &GraphViewSettingItem::setColor);
  31. connect(colorButton, &ColorButton::colorChanged, this, &GraphViewSettingItem::setColor);
  32. connect(ui.NameEdit, &QLineEdit::textChanged, [=](const QString& text) { series->description = text; updateGroupBoxTitle(); });
  33. }
  34. GraphViewSettingItem::~GraphViewSettingItem()
  35. {
  36. }
  37. void GraphViewSettingItem::dissableSlidersOnType()
  38. {
  39. switch (series->type) {
  40. case GraphPlottSeries::SeriesType::Line:
  41. ui.LineSlider->setEnabled(true);
  42. ui.CircleSlider->setEnabled(false);
  43. break;
  44. case GraphPlottSeries::SeriesType::Dot:
  45. ui.LineSlider->setEnabled(false);
  46. ui.CircleSlider->setEnabled(true);
  47. break;
  48. case GraphPlottSeries::SeriesType::LineDot:
  49. ui.LineSlider->setEnabled(true);
  50. ui.CircleSlider->setEnabled(true);
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. void GraphViewSettingItem::setType(int type)
  57. {
  58. switch (type) {
  59. case 0:
  60. series->type = GraphPlottSeries::SeriesType::Line;
  61. break;
  62. case 1:
  63. series->type = GraphPlottSeries::SeriesType::Dot;
  64. break;
  65. case 2:
  66. series->type = GraphPlottSeries::SeriesType::LineDot;
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. void GraphViewSettingItem::setColor(QColor color)
  73. {
  74. series->color = color;
  75. updateGroupBoxTitle();
  76. view->update();
  77. }
  78. void GraphViewSettingItem::updateGroupBoxTitle()
  79. {
  80. ui.GroupBox->setTitle("Series: " + series->description);
  81. QString style = "QGroupBox { color: rgb(%1, %2, %3); };";
  82. ui.GroupBox->setStyleSheet(style.arg(series->color.red()).arg(series->color.green()).arg(series->color.blue()));
  83. }