Skip to content

Commit

Permalink
fixed issue 7 (segfault when no plant and plot is selected)
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelG committed Aug 28, 2015
1 parent b306db9 commit afa6e65
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/plants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Plant* Plants::find(const std::string& key)
return plant_up.get();
}
}
return NULL;
return nullptr;
}

void Plants::remove(int iplant)
Expand Down
10 changes: 10 additions & 0 deletions src/gui/gui_widgets/EditCropWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ void EditCropWidget::edit_crop()
{
QString plot_key = ui->plotInput->currentElem();
Plot* p_plot = dataset.get_plots().find(fromQString(plot_key));
if (p_plot == nullptr) {
QMessageBox::critical(NULL, QObject::tr("Error"),
QObject::tr("Please select a plot."));
return;
}
Rectangle rect = ui->shapeInput->get_rect();

QString plant_key = ui->plantInput->currentElem();
Plant* p_plant = dataset.get_plants().find(fromQString(plant_key));
if (p_plant == nullptr) {
QMessageBox::critical(NULL, QObject::tr("Error"),
QObject::tr("Please select a plant."));
return;
}
QString var_key = ui->varInput->currentElem();

QDate start_date = ui->startdateInput->selectedDate();
Expand Down
6 changes: 6 additions & 0 deletions src/gui/gui_widgets/PlantsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ QVariant PlantsModel::data(const QModelIndex& index, int role) const
{
if (! index.parent().isValid()) // parent is invalid: we want the plant
{
if (index.row() >= plants.size() || index.row() < 0) {
return QVariant();
}
if (role == Qt::DisplayRole)
{
if (index.column() == 0)
Expand All @@ -82,6 +85,9 @@ QVariant PlantsModel::data(const QModelIndex& index, int role) const
else
{
int plant_index = index.parent().row();
if (plant_index >= plants.size() || plant_index < 0) {
return QVariant();
}
if (role == Qt::DisplayRole)
{
if (index.column() == 0)
Expand Down
4 changes: 4 additions & 0 deletions src/gui/gui_widgets/PlotsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ int PlotsModel::columnCount(const QModelIndex& index) const

QVariant PlotsModel::data(const QModelIndex& index, int role) const
{
if (index.row() >= plots.size() || index.row() < 0) {
return QVariant();
}

if (role == Qt::DisplayRole)
{
if (index.column() == 0)
Expand Down
26 changes: 19 additions & 7 deletions tomate_fr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="fr_FR">
<TS version="2.1" language="fr_FR">
<context>
<name>AddDialog</name>
<message>
Expand Down Expand Up @@ -247,22 +247,22 @@
<context>
<name>PhysInput</name>
<message>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="37"/>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="62"/>
<source>x position:</source>
<translation>position x :</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="39"/>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="64"/>
<source>y position:</source>
<translation>position y :</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="41"/>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="66"/>
<source>width:</source>
<translation>largeur :</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="43"/>
<location filename="src/gui/gui_widgets/PhysInput.cpp" line="68"/>
<source>height:</source>
<translation>hauteur :</translation>
</message>
Expand Down Expand Up @@ -337,6 +337,8 @@
<location filename="src/main.cpp" line="38"/>
<location filename="src/main.cpp" line="59"/>
<location filename="src/main.cpp" line="81"/>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="78"/>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="87"/>
<source>Error</source>
<translation>Erreur</translation>
</message>
Expand Down Expand Up @@ -366,12 +368,22 @@
<translation>Erreur d&apos;écriture du fichier de données.</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="115"/>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="79"/>
<source>Please select a plot.</source>
<translation>Veuillez sélectionner une planche.</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="88"/>
<source>Please select a plant.</source>
<translation>Veuillez sélectionner une plante.</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="125"/>
<source>Delete crop</source>
<translation>Suppression d&apos;une culture</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="116"/>
<location filename="src/gui/gui_widgets/EditCropWidget.cpp" line="126"/>
<source>Are you sure you want to delete the crop ?</source>
<translation>Êtes-vous sûr de vouloir supprimer cette culture ?</translation>
</message>
Expand Down

0 comments on commit afa6e65

Please sign in to comment.