Skip to content

Commit

Permalink
Merge pull request #56 from UmbrellaLeaf5/gui_mistakes_fix
Browse files Browse the repository at this point in the history
gui mistakes fix
  • Loading branch information
Stargazer2005 authored Apr 23, 2024
2 parents a7cae97 + 3c530c0 commit 763597a
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 252 deletions.
331 changes: 166 additions & 165 deletions data_tools/tables_connection/tables_connection.cpp

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion gui/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ namespace gui {
/// @brief Некоторая возможная к рисованию фигура [абстрактный класс]
class Drawable {
public:
Drawable() = default;

/**
* @brief Привязывает (рисует) экземпляр класса на полотне
* @param plot: указатель на соотв. полотно
*/
virtual void Draw(QCustomPlot* plot) = 0;

Drawable() = default;
/**
* @brief Возвращает индекс на полотне [plottable]
* @return size_t: индекс
*/
virtual size_t GetIndexOnPlot() const { return index_on_plot_; }

protected:
virtual void SetIndexOnPlot(QCustomPlot* plot) {
index_on_plot_ = plot->plottableCount() - 1;
}

private:
size_t index_on_plot_{ULLONG_MAX};
};

// @brief Типы объектов по категориям
Expand Down
2 changes: 1 addition & 1 deletion gui/hill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ void gui::Hill::Draw(QCustomPlot* plot) {
curve_->addData(points[0].x, points[0].y);

// индекс последнего созданного = кол-во всех - 1
plottable_index_ = plot->plottableCount() - 1;
SetIndexOnPlot(plot);
}
8 changes: 1 addition & 7 deletions gui/hill.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ class Hill : public Drawable {

void Draw(QCustomPlot* plot) override;

/**
* @brief Возвращает индекс на полотне [plottable]
* @return size_t: индекс
*/
size_t GetPlottableIndex() const { return plottable_index_; }

/**
* @brief Возвращает значение указателя на полотне
* @return QCPGraph*: указатель
Expand All @@ -70,7 +64,7 @@ class Hill : public Drawable {
private:
lib::Hill data_;
QColor color_;
size_t plottable_index_{ULLONG_MAX};

QCPCurve* curve_{nullptr};
};

Expand Down
2 changes: 1 addition & 1 deletion gui/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ void gui::Target::Draw(QCustomPlot* plot) {
graph_->setData({GetPoint().x}, {GetPoint().y});

// индекс последнего созданного = кол-во всех - 1
plottable_index_ = plot->plottableCount() - 1;
SetIndexOnPlot(plot);
}
8 changes: 1 addition & 7 deletions gui/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ class Target : public Drawable {

void Draw(QCustomPlot* plot) override;

/**
* @brief Возвращает индекс на полотне [plottable]
* @return size_t: индекс
*/
size_t GetPlottableIndex() const { return plottable_index_; }

/**
* @brief Возвращает значение указателя на полотне
* @return QCPGraph*: указатель
Expand All @@ -43,7 +37,7 @@ class Target : public Drawable {

private:
lib::Target data_;
size_t plottable_index_{ULLONG_MAX};

QCPGraph* graph_{nullptr};
};

Expand Down
2 changes: 1 addition & 1 deletion gui/trappy_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ void gui::TrappyCircle::Draw(QCustomPlot* plot) {
GetCenter().y - GetRadius());

// индекс последнего созданного = кол-во всех - 1
item_index_ = plot->itemCount() - 1;
SetIndexOnPlot(plot);
}
9 changes: 8 additions & 1 deletion gui/trappy_circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class TrappyCircle : public Drawable {

/**
* @brief Возвращает индекс на полотне [item]
* @details Этот метод перегружен у TrappyCircle, так как его фигуры на
* полотне являются QCPItemEllipse, которые в свою очередь относятся к Items,
* а не Plottables по отношению к QCustomPlot plot
* @return size_t: индекс
*/
size_t GetItemIndex() const { return item_index_; }
size_t GetIndexOnPlot() const override { return item_index_; }

/**
* @brief Возвращает значение указателя на полотне
Expand All @@ -52,6 +55,10 @@ class TrappyCircle : public Drawable {
QCPItemEllipse* GetItemEllipsePtr() const { return ellipse_; }

private:
void SetIndexOnPlot(QCustomPlot* plot) override {
item_index_ = plot->itemCount() - 1;
}

lib::TrappyCircle data_;
QColor color_;
size_t item_index_{ULLONG_MAX};
Expand Down
2 changes: 1 addition & 1 deletion gui/trappy_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void TrappyLine::Draw(QCustomPlot* plot) {
graph_->addData(targets.second.GetPoint().x, targets.second.GetPoint().y);

// индекс последнего созданного = кол-во всех - 1
plottable_index_ = plot->plottableCount() - 1;
SetIndexOnPlot(plot);
}

void TrappyLine::UpdateData(gui::Target* first_target,
Expand Down
8 changes: 1 addition & 7 deletions gui/trappy_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ class TrappyLine : public Drawable {

void Draw(QCustomPlot* plot) override;

/**
* @brief Возвращает индекс на полотне [plottable]
* @return size_t: индекс
*/
size_t GetPlottableIndex() const { return plottable_index_; }

/**
* @brief Возвращает значение указателя на полотне
* @return QCPGraph*: указатель
Expand All @@ -74,7 +68,7 @@ class TrappyLine : public Drawable {
void UpdateData(std::pair<gui::Target*, gui::Target*> targets);

lib::TrappyLine data_;
size_t plottable_index_{ULLONG_MAX};

QCPGraph* graph_{nullptr};

// самый простой способ иметь доступ из TrappyLine к привязанным к.т.
Expand Down
4 changes: 2 additions & 2 deletions lib/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace lib {
/// @brief Объект, возможный к считыванию по .json файлу [абстрактный класс]
class JSONable {
public:
virtual QJsonObject Load(int id) const = 0;
virtual void Save(const QJsonObject& obj) = 0;
virtual QJsonObject GetJsonInfo(int id) const = 0;
virtual void SetJsonInfo(const QJsonObject& obj) = 0;
virtual bool IsChanged(const QJsonObject& obj) const = 0;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/hill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Hill::Hill(std::initializer_list<Point> points) : vertices_{points} {
throw std::invalid_argument("hill cannot consist of one or zero points");
}

QJsonObject Hill::Load(int id) const {
QJsonObject Hill::GetJsonInfo(int id) const {
QVariantMap hill_map;
hill_map.insert("Id", id);

Expand All @@ -27,7 +27,7 @@ QJsonObject Hill::Load(int id) const {
return QJsonObject::fromVariantMap(hill_map);
}

void Hill::Save(const QJsonObject& hill_obj) {
void Hill::SetJsonInfo(const QJsonObject& hill_obj) {
if (!hill_obj.contains("Vertices")) throw std::invalid_argument("");
QJsonArray vertices_array = hill_obj.value("Vertices").toArray();
for (size_t i = 0; i < vertices_array.size(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/hill.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Hill : public JSONable {
Hill& operator=(const Hill&) = default;
Hill& operator=(Hill&&) = default;

QJsonObject Load(int id) const override;
void Save(const QJsonObject& hill_obj) override;
QJsonObject GetJsonInfo(int id) const override;
void SetJsonInfo(const QJsonObject& hill_obj) override;
bool IsChanged(const QJsonObject& hill_obj) const override;

Point GetCenter() const;
Expand Down
4 changes: 2 additions & 2 deletions lib/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace lib {

QJsonObject Target::Load(int id) const {
QJsonObject Target::GetJsonInfo(int id) const {
QVariantMap target_map;

target_map.insert("Id", id);
Expand All @@ -12,7 +12,7 @@ QJsonObject Target::Load(int id) const {
return QJsonObject::fromVariantMap(target_map);
}

void Target::Save(const QJsonObject& target_obj) {
void Target::SetJsonInfo(const QJsonObject& target_obj) {
if (!(target_obj.contains("X") && target_obj.contains("Y")))
throw std::invalid_argument("");
double x = target_obj.value("X").toDouble();
Expand Down
4 changes: 2 additions & 2 deletions lib/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Target : public JSONable {
Target& operator=(const Target&) = default;
Target& operator=(Target&&) = default;

QJsonObject Load(int id) const override;
void Save(const QJsonObject& target_obj) override;
QJsonObject GetJsonInfo(int id) const override;
void SetJsonInfo(const QJsonObject& target_obj) override;
bool IsChanged(const QJsonObject& target_obj) const override;

Point GetPoint() const { return p_; }
Expand Down
4 changes: 2 additions & 2 deletions lib/trappy_circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TrappyCircle::TrappyCircle(Point center, double radius)
throw std::invalid_argument("trappy circle cannot have of negative radius");
}

QJsonObject TrappyCircle::Load(int id) const {
QJsonObject TrappyCircle::GetJsonInfo(int id) const {
QVariantMap trappy_circle_map;

trappy_circle_map.insert("Id", id);
Expand All @@ -21,7 +21,7 @@ QJsonObject TrappyCircle::Load(int id) const {
return QJsonObject::fromVariantMap(trappy_circle_map);
}

void TrappyCircle::Save(const QJsonObject& trappy_circle_obj) {
void TrappyCircle::SetJsonInfo(const QJsonObject& trappy_circle_obj) {
if (!(trappy_circle_obj.contains("X") && trappy_circle_obj.contains("Y") &&
trappy_circle_obj.contains("Radius")))
throw std::invalid_argument("");
Expand Down
4 changes: 2 additions & 2 deletions lib/trappy_circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class TrappyCircle : public JSONable {
TrappyCircle& operator=(const TrappyCircle&) = default;
TrappyCircle& operator=(TrappyCircle&&) = default;

QJsonObject Load(int id) const override;
void Save(const QJsonObject& trappy_circle_obj) override;
QJsonObject GetJsonInfo(int id) const override;
void SetJsonInfo(const QJsonObject& trappy_circle_obj) override;
bool IsChanged(const QJsonObject& trappy_circle_obj) const override;

Point GetCenter() const { return center_; }
Expand Down
4 changes: 2 additions & 2 deletions lib/trappy_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace lib {

QJsonObject TrappyLine::Load(int id) const {
QJsonObject TrappyLine::GetJsonInfo(int id) const {
QVariantMap trappy_line_map;
QVariantMap p1_map;
QVariantMap p2_map;
Expand All @@ -22,7 +22,7 @@ QJsonObject TrappyLine::Load(int id) const {
return QJsonObject::fromVariantMap(trappy_line_map);
}

void TrappyLine::Save(const QJsonObject& trappy_line_obj) {
void TrappyLine::SetJsonInfo(const QJsonObject& trappy_line_obj) {
if (!(trappy_line_obj.contains("P1") && trappy_line_obj.contains("P2")))
throw std::invalid_argument("");

Expand Down
4 changes: 2 additions & 2 deletions lib/trappy_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class TrappyLine : public JSONable {
TrappyLine& operator=(const TrappyLine&) = default;
TrappyLine& operator=(TrappyLine&&) = default;

QJsonObject Load(int id) const override;
void Save(const QJsonObject& trappy_line_obj) override;
QJsonObject GetJsonInfo(int id) const override;
void SetJsonInfo(const QJsonObject& trappy_line_obj) override;
bool IsChanged(const QJsonObject& trappy_line_obj) const override;

void SetTargets(Target* first_target, Target* second_target) {
Expand Down
8 changes: 4 additions & 4 deletions main/gui_json_file/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ std::vector<lib::Target> GetTargetsFromFile(QJsonArray arr,
std::vector<lib::Target> targets;
for (size_t i = 0; i < arr.size(); i++) {
lib::Target t;
t.Save(arr.at(i).toObject());
t.SetJsonInfo(arr.at(i).toObject());
targets.push_back(t);
}

Expand All @@ -17,7 +17,7 @@ std::vector<lib::TrappyCircle> GetTrappyCirclesFromFile(
std::vector<lib::TrappyCircle> trappy_circles;
for (size_t i = 0; i < arr.size(); i++) {
lib::TrappyCircle tc;
tc.Save(arr.at(i).toObject());
tc.SetJsonInfo(arr.at(i).toObject());
trappy_circles.push_back(tc);
}

Expand All @@ -29,7 +29,7 @@ std::vector<lib::TrappyLine> GetTrappyLinesFromFile(
std::vector<lib::TrappyLine> trappy_lines;
for (size_t i = 0; i < arr.size(); i++) {
lib::TrappyLine tl;
tl.Save(arr.at(i).toObject());
tl.SetJsonInfo(arr.at(i).toObject());
trappy_lines.push_back(tl);
}

Expand All @@ -41,7 +41,7 @@ std::vector<lib::Hill> GetHillsFromFile(QJsonArray arr,
std::vector<lib::Hill> hills;
for (size_t i = 0; i < arr.size(); i++) {
lib::Hill h;
h.Save(arr.at(i).toObject());
h.SetJsonInfo(arr.at(i).toObject());
hills.push_back(h);
}

Expand Down
17 changes: 9 additions & 8 deletions main/gui_json_file/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@ void GuiJsonFile::Save(data_tools::DataManager* manager) {
int add_to_id = 10000;

for (size_t i = 0; i < manager->GetTargets().size(); i++) {
int id = add_to_id + manager->GetTargets()[i].GetPlottableIndex();
targets_array.append(manager->GetTargets()[i].GetData().Load(id));
int id = add_to_id + manager->GetTargets()[i].GetIndexOnPlot();
targets_array.append(manager->GetTargets()[i].GetData().GetJsonInfo(id));
}
root.insert("Targets", targets_array);

add_to_id = 20000;

for (size_t i = 0; i < manager->GetTrappyCircles().size(); i++) {
int id = add_to_id + manager->GetTrappyCircles()[i].GetItemIndex();
int id = add_to_id + manager->GetTrappyCircles()[i].GetIndexOnPlot();
trappy_circles_array.append(
manager->GetTrappyCircles()[i].GetData().Load(id));
manager->GetTrappyCircles()[i].GetData().GetJsonInfo(id));
}
root.insert("Trappy_Circles", trappy_circles_array);

add_to_id = 30000;

for (size_t i = 0; i < manager->GetTrappyLines().size(); i++) {
int id = add_to_id + manager->GetTrappyLines()[i].GetPlottableIndex();
trappy_lines_array.append(manager->GetTrappyLines()[i].GetData().Load(id));
int id = add_to_id + manager->GetTrappyLines()[i].GetIndexOnPlot();
trappy_lines_array.append(
manager->GetTrappyLines()[i].GetData().GetJsonInfo(id));
}
root.insert("Trappy_Lines", trappy_lines_array);

add_to_id = 40000;

for (size_t i = 0; i < manager->GetHills().size(); i++) {
int id = add_to_id + manager->GetHills()[i].GetPlottableIndex();
hills_array.append(manager->GetHills()[i].GetData().Load(id));
int id = add_to_id + manager->GetHills()[i].GetIndexOnPlot();
hills_array.append(manager->GetHills()[i].GetData().GetJsonInfo(id));
}
root.insert("Hills", hills_array);

Expand Down
4 changes: 2 additions & 2 deletions main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ MainWindow::MainWindow(QWidget* parent)
ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |
QCP::iSelectPlottables | QCP::iSelectItems);

connect(ui->plot, SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
SLOT(mousePressObjectsButton(QMouseEvent*)));
connect(ui->plot, &QCustomPlot::mouseDoubleClick, this,
&MainWindow::mousePressObjectsButton);

area_->Setup(manager_.get());
t_connection_->Setup(manager_.get(), area_.get());
Expand Down
Loading

0 comments on commit 763597a

Please sign in to comment.