Skip to content

Commit

Permalink
Targets can be deleted now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowen committed Jan 8, 2015
1 parent 20be0f5 commit 6c88900
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
5 changes: 2 additions & 3 deletions groundstation/mainpic/mainpicdisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MainPicDisplay.h"
using namespace std;

MainPicDisplay::MainPicDisplay(const QVector<Target>* itargets, QWidget *parent) :
MainPicDisplay::MainPicDisplay(const QVector<Target>& itargets, QWidget *parent) :
QLabel(parent), TARGET_DRAW_SIZE(10), targets(itargets)
{
setScaledContents(true);
Expand Down Expand Up @@ -90,8 +90,7 @@ void MainPicDisplay::paintEvent(QPaintEvent *event){
painter.setBrush(QBrush(gradient));

// Draw all targets
for (int i = 0; i < targets->size(); i++){
const Target& t = targets->at(i);
foreach (Target t, targets){
int x = t["x"].toInt() / getZoomFactor() - TARGET_DRAW_SIZE/2;
int y = t["y"].toInt() / getZoomFactor() - TARGET_DRAW_SIZE/2;
painter.setBrushOrigin(x, y);
Expand Down
4 changes: 2 additions & 2 deletions groundstation/mainpic/mainpicdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MainPicDisplay: public QLabel
{
Q_OBJECT
public:
explicit MainPicDisplay(const QVector<Target>*, QWidget *parent = 0);
explicit MainPicDisplay(const QVector<Target>&, QWidget *parent = 0);
~MainPicDisplay();

void setMaxSize(const int&, const int&);
Expand All @@ -37,7 +37,7 @@ class MainPicDisplay: public QLabel
int maxHeight;

int TARGET_DRAW_SIZE;
const QVector<Target>* targets;
const QVector<Target>& targets;

signals:
void clicked(int x, int y);
Expand Down
29 changes: 28 additions & 1 deletion groundstation/mainpic/mainpicwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MainPicWidget::MainPicWidget(QWidget *parent) :
layout->addWidget(scrollArea);

// The pic display area
picDisplay = new MainPicDisplay(&targets, this);
picDisplay = new MainPicDisplay(targets, this);
scrollArea->setWidget(picDisplay);
connect(picDisplay, SIGNAL(clicked(int, int)), this, SLOT(onPictureClicked(int, int)));

Expand Down Expand Up @@ -41,6 +41,14 @@ MainPicWidget::MainPicWidget(QWidget *parent) :
QPushButton *toggleMode = new QPushButton("Select targets");
connect(toggleMode, SIGNAL(pressed()), this, SLOT(toggleMode()));
cpLayout->addWidget(toggleMode, 2, 2);
// Enhance
QPushButton *enhanceButton = new QPushButton("Enhance Button");
connect(enhanceButton, SIGNAL(pressed()), this, SLOT(deleteTarget()));
cpLayout->addWidget(enhanceButton, 1, 3);
// delete targets pls no ocd
QPushButton *deleteTarget = new QPushButton("Delete target");
connect(deleteTarget, SIGNAL(pressed()), this, SLOT(deleteTarget()));
cpLayout->addWidget(deleteTarget, 2, 3);

// Target Table
targetTable = new QTableWidget();
Expand Down Expand Up @@ -127,3 +135,22 @@ void MainPicWidget::addTargetToTable(const Target& target){
targetTable->setItem(row, column, new QTableWidgetItem(target[Target::FIELD_NAMES[column]].toString()));
}
}

//delete targets pls no ocd
void MainPicWidget::deleteTarget(){
int row = targetTable->currentRow();
if (row >= 0){
//int x = targetTable->item(row, 1)->text();
//int y = targetTable->item(row, 2)->text();
targets.removeAt(row);
targetTable->removeRow(row);
picDisplay->update();
// Try to save the new targets into the file
try{
targetFileHandler.saveFile(targets, currentPicture + TargetFileHandler::fileExtension);
}catch(TargetFileHandler::FileWriteException e){
qDebug() << e.what();
// TODO actual error handling
}
}
}
1 change: 1 addition & 0 deletions groundstation/mainpic/mainpicwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MainPicWidget : public QWidget

public slots:
void toggleMode();
void deleteTarget();
void onPictureClicked(int x, int y);
void onTargetTableChanged(int row, int column);
};
Expand Down

0 comments on commit 6c88900

Please sign in to comment.