Skip to content

Commit

Permalink
select crops from space view or time view, plants and plots edit in m…
Browse files Browse the repository at this point in the history
…odal windows
  • Loading branch information
MickaelG committed Mar 25, 2014
1 parent 551950e commit 88194f2
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 133 deletions.
54 changes: 30 additions & 24 deletions src/gui/gui_mainwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,69 @@
#include "gui_plots.h"
#include "gui_spaceview.h"
#include "gui_timeline.h"
#include "EditCropWidget.h"

#include "xml.h"

#include <QGridLayout>
#include <QToolBar>

QTabWidget* createTabsWidget(Dataset& data)
QWidget* createTabsWidget(Dataset& data)
{
QTabWidget* widget = new QTabWidget;
QTabWidget* tab_widget = new QTabWidget;

SpaceViewWindow* spacewidget = new SpaceViewWindow(data);
widget->addTab(spacewidget, QObject::tr("Space view"));
tab_widget->addTab(spacewidget, QObject::tr("Space view"));

TimelineWindow* timewidget = new TimelineWindow(data);
widget->addTab(timewidget, QObject::tr("Time view"));
tab_widget->addTab(timewidget, QObject::tr("Time view"));

PlantsWindow* plantswidget = new PlantsWindow(data.get_plants());
widget->addTab(plantswidget, QObject::tr("Plants"));

PlotsWindow* plotswidget = new PlotsWindow(data.get_plots());
widget->addTab(plotswidget, QObject::tr("Plots"));

EditCropWidget* edit_crop_widget = new EditCropWidget(data);

QObject::connect(plantswidget, SIGNAL(timeline_need_update()), spacewidget, SLOT(update_draw()));
QObject::connect(plantswidget, SIGNAL(timeline_need_update()), timewidget, SLOT(update()));
QObject::connect(plantswidget, SIGNAL(timeline_need_update()), timewidget, SLOT(update_draw()));

QObject::connect(plotswidget, SIGNAL(timeline_need_update()), spacewidget, SLOT(update_draw()));
QObject::connect(plotswidget, SIGNAL(timeline_need_update()), timewidget, SLOT(update()));
QObject::connect(plotswidget, SIGNAL(timeline_need_update()), timewidget, SLOT(update_draw()));

QObject::connect(edit_crop_widget, SIGNAL(dataset_changed()), timewidget, SLOT(update_draw()));
QObject::connect(edit_crop_widget, SIGNAL(dataset_changed()), spacewidget, SLOT(update_draw()));

//QObject::connect(timewidget->get_view()->get_scene()->get_ecd(), SIGNAL(dataset_changed()), timewidget, SLOT(update_draw()));
//QObject::connect(timewidget->get_view()->get_scene()->get_ecd(), SIGNAL(dataset_changed()), spacewidget, SLOT(update_draw()));
//Date of the spacewidget
QObject::connect(timewidget->get_view()->get_scene(), SIGNAL(current_date_changed(QDate)), spacewidget->get_view()->get_scene(), SLOT(set_date(QDate)));

//Crops selection synchronisation
QObject::connect(timewidget->get_view()->get_scene(), SIGNAL(crop_selected(Crop*)), edit_crop_widget, SLOT(set_crop_values(Crop*)));
QObject::connect(spacewidget->get_view()->get_scene(), SIGNAL(crop_selected(Crop*)), edit_crop_widget, SLOT(set_crop_values(Crop*)));
QObject::connect(timewidget->get_view()->get_scene(), SIGNAL(crop_selected(Crop*)),
spacewidget->get_view()->get_scene(), SLOT(selectCrop(Crop*)));
QObject::connect(spacewidget->get_view()->get_scene(), SIGNAL(crop_selected(Crop*)),
timewidget->get_view()->get_scene(), SLOT(selectCrop(Crop*)));

QObject::connect(edit_crop_widget->ui->EditPlantsBtn, SIGNAL(clicked()), plantswidget, SLOT(show()));
QObject::connect(edit_crop_widget->ui->EditPlotsBtn, SIGNAL(clicked()), plotswidget, SLOT(show()));

QWidget* widget = new QWidget;
QGridLayout* main_layout = new QGridLayout;
main_layout->addWidget(tab_widget);
main_layout->addWidget(edit_crop_widget);
widget->setLayout(main_layout);

return widget;
}


GuiMainWin::GuiMainWin(Dataset& dataset) : dataset(dataset) {
showMaximized();

/*
QToolBar* toolbar = new QToolBar();
QAction* write_action = toolbar->addAction(tr("Write"));
QObject::connect(write_action, SIGNAL(triggered()), this, SLOT(write_file()));
addToolBar(toolbar);
*/

setCentralWidget(new QWidget);
centralWidget()->setLayout(new QGridLayout);
centralWidget()->layout()->addWidget(createTabsWidget(dataset));
}

void GuiMainWin::write_file()
{
xml_write_data("../user_data/data_out.sfg", dataset);
}


GuiMainWin::~GuiMainWin() {
//TODO: delete tabwidget, timewidget, plantswidget, spacewidget
}
Expand Down
3 changes: 0 additions & 3 deletions src/gui/gui_mainwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class GuiMainWin : public QMainWindow
GuiMainWin(Dataset& dataset);
~GuiMainWin();

private slots:
void write_file();

private:
Dataset& dataset;
};
8 changes: 7 additions & 1 deletion src/gui/gui_plants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ vector<QString> PlantsWindow::plants_str_list()
}

PlantsWindow::PlantsWindow(Plants& plants, QWidget* parent) :
QWidget(parent), plants(plants)
QDialog(parent), plants(plants)
{
setModal(true);

color_dialog = new QColorDialog;
QVBoxLayout* plants_layout = new QVBoxLayout();
vector<QString> plants_str = plants_str_list();
Expand All @@ -107,6 +109,10 @@ PlantsWindow::PlantsWindow(Plants& plants, QWidget* parent) :
plants_layout->addWidget(add_plant_btn);
plants_layout->addWidget(del_plant_btn);

QPushButton* close_btn = new QPushButton(tr("Close"));
plants_layout->addWidget(close_btn);
QObject::connect(close_btn, SIGNAL(clicked()), this, SLOT(accept()));

QVBoxLayout* var_layout = new QVBoxLayout();
var_widget = new QListView();
var_widget->setModel(new VarsModel(plants, plants_widget));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gui_plants.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private slots:
QLineEdit* nameInput;
};

class PlantsWindow: public QWidget
class PlantsWindow: public QDialog
{
Q_OBJECT

Expand Down
8 changes: 7 additions & 1 deletion src/gui/gui_plots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ void AddPlotDialog::add()


PlotsWindow::PlotsWindow(Plots& plots, QWidget* parent) :
QWidget(parent), plots(plots)
QDialog(parent), plots(plots)
{
setModal(true);

QVBoxLayout* plots_layout = new QVBoxLayout();
plots_widget = new ListWidget(new PlotsModel(plots));
plots_layout->addWidget(plots_widget);
Expand All @@ -69,6 +71,10 @@ PlotsWindow::PlotsWindow(Plots& plots, QWidget* parent) :
QObject::connect(del_plot_btn, SIGNAL(clicked()), this, SLOT(delete_plot()));
plots_layout->addWidget(del_plot_btn);

QPushButton* close_btn = new QPushButton(tr("Close"));
plots_layout->addWidget(close_btn);
QObject::connect(close_btn, SIGNAL(clicked()), this, SLOT(accept()));

QObject::connect(add_plot, SIGNAL(list_updated()), plots_widget->model(), SIGNAL(layoutChanged()));
QObject::connect(this, SIGNAL(plots_widget_layoutAboutToBeChanged()), plots_widget->model(), SIGNAL(layoutAboutToBeChanged()));
QObject::connect(add_plot, SIGNAL(list_updated()), this, SIGNAL(timeline_need_update()));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gui_plots.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private slots:
QLineEdit* horInput;
};

class PlotsWindow: public QWidget
class PlotsWindow: public QDialog
{
Q_OBJECT

Expand Down
97 changes: 93 additions & 4 deletions src/gui/gui_spaceview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QFont>
#include <QColor>
#include <QBrush>
#include <QGraphicsSceneMouseEvent>

SpaceViewWindow::SpaceViewWindow(Dataset& dataset) : view(dataset, this)
{
Expand Down Expand Up @@ -38,18 +39,17 @@ void WholeSceneView::zoom_fit()
}

void WholeSceneView::resizeEvent(QResizeEvent *event)

{
zoom_fit();
}

PlotRepresentation::PlotRepresentation(Crops& crops, Plot& plot, QDate date) :
crops(crops), plot(plot)
{
this->update(date);
this->update_draw(date);
}

void PlotRepresentation::update(QDate date)
void PlotRepresentation::update_draw(QDate date)
{
Rectangle rect = plot.get_rect();
this->setRect(rect.get_x(), - rect.get_y() - rect.get_height(),
Expand All @@ -60,6 +60,7 @@ void PlotRepresentation::update(QDate date)
SubdRepresentation *subd_repr = new SubdRepresentation(subd.get_rect(), crop, date);
subd_repr->setPos(rect.get_x(), -rect.get_y());
subd_repr->setParentItem(this);
subd_reprs.push_back(subd_repr);
}
}
//TODO: delete subd_repr
Expand Down Expand Up @@ -95,9 +96,15 @@ SubdRepresentation::SubdRepresentation(Rectangle rect, Crop& crop, QDate date) :
}
}

Crop* SubdRepresentation::get_pcrop()
{
return &crop;
}

WholeScene::WholeScene(Dataset& dataset) : dataset(dataset)
{
date = QDate::currentDate();
selected_subd_repr = 0;
this->draw_scene();
}

Expand All @@ -109,7 +116,7 @@ void WholeScene::set_date(QDate date)

void WholeScene::update_draw()
{
this->clear();
this->clear_scene();
this->draw_scene();
}

Expand All @@ -122,7 +129,89 @@ void WholeScene::draw_scene()
PlotRepresentation *plot_repr = new PlotRepresentation(dataset.get_crops(),
plot, date);
this->addItem(plot_repr);
plot_reprs.push_back(plot_repr);
//TODO: delete plot_repr
}
}
}

void WholeScene::clear_scene()
{
selected_subd_repr = 0;
plot_reprs.clear();
clear();
}

Crop* WholeScene::getCropAtPos(QPointF scene_pos)
{
Crop* p_current_crop = 0;
for (PlotRepresentation* plot_repr: plot_reprs)
{
for (SubdRepresentation* subd_repr: plot_repr->subd_reprs)
{
QRectF subd_rect = subd_repr->sceneTransform().mapRect(subd_repr->boundingRect());
if (subd_rect.contains(scene_pos))
{
if (subd_repr->get_pcrop() != &NullCrop)
{
p_current_crop = subd_repr->get_pcrop();
}
return p_current_crop;
}
}
}
return p_current_crop;
}

void WholeScene::drawCropSelection()
{
if (selected_crop && !selected_subd_repr)
{
for (PlotRepresentation* plot_repr: plot_reprs)
{
for (SubdRepresentation* subd_repr: plot_repr->subd_reprs)
{
if (subd_repr->get_pcrop() == selected_crop)
{
selected_subd_repr = subd_repr;
break;
}
}
}
}
if (selected_subd_repr)
{
QPen selected_pen;
float scene_scale = views()[0]->transform().m11();
float pen_width = 4 / scene_scale;
selected_pen.setWidthF(pen_width);
//selected_pen.setColor(QColor("#444444"));
selected_subd_repr->setZValue(1);
selected_subd_repr->setPen(selected_pen);
}
}

void WholeScene::removeCropSelection()
{
if (selected_subd_repr)
{
selected_subd_repr->setZValue(0);
selected_subd_repr->setPen(QPen());
}
}

void WholeScene::selectCrop(Crop* p_crop)
{
removeCropSelection();
selected_subd_repr = 0;
selected_crop = p_crop;
drawCropSelection();
}

void WholeScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPointF clic_point = event->scenePos();
Crop* p_current_crop = getCropAtPos(clic_point);
selectCrop(p_current_crop);
emit crop_selected(selected_crop);
}
Loading

0 comments on commit 88194f2

Please sign in to comment.