Commit e14bfb7e authored by roangel's avatar roangel
Browse files

now we are creating cf zones whenever they are in database and not in GUI

parent 6e29ce67
......@@ -44,6 +44,8 @@ public:
void removeTable();
void addCFZone(QRectF rect, int index);
public slots:
void removeCrazyFlyZone(int cf_zone_index);
void setSelectedCrazyFlyZone(int index);
......
......@@ -712,6 +712,32 @@ void MainGUIWindow::on_load_from_DB_button_clicked()
std::string cf_name = m_data_base.crazyflieEntries[i].crazyflieContext.crazyflieName;
int cf_zone_index = m_data_base.crazyflieEntries[i].crazyflieContext.localArea.crazyfly_zone_index;
// we should first create the cf zones that are in the database?
bool cf_zone_exists;
qreal width = m_data_base.crazyflieEntries[i].crazyflieContext.localArea.xmax - m_data_base.crazyflieEntries[i].crazyflieContext.localArea.xmin;
qreal height = m_data_base.crazyflieEntries[i].crazyflieContext.localArea.ymax - m_data_base.crazyflieEntries[i].crazyflieContext.localArea.ymin;
QRectF tmp_rect(m_data_base.crazyflieEntries[i].crazyflieContext.localArea.xmin,
m_data_base.crazyflieEntries[i].crazyflieContext.localArea.ymax,
width,
height);
int found_j;
for(int j = 0; j < scene->crazyfly_zones.size(); j++)
{
if(cf_zone_index == scene->crazyfly_zones[j]->getIndex())
{
cf_zone_exists = true;
found_j = j;
break;
}
}
if(!cf_zone_exists)
{
scene->addCFZone(tmp_rect, cf_zone_index);
}
else
{
scene->crazyfly_zones[found_j]->setRect(tmp_rect);
scene->crazyfly_zones[found_j]->rectSizeChanged();
}
int student_id = m_data_base.crazyflieEntries[i].studentID;
cf_linker->link(student_id, cf_zone_index, cf_name);
}
......
......@@ -95,6 +95,17 @@ int myGraphicsScene::checkSelectedCrazyFlyZone()
return -1;
}
void myGraphicsScene::addCFZone(QRectF rect, int index)
{
tmp_crazyfly_zone_item = new crazyFlyZone(rect, index);
addItem(tmp_crazyfly_zone_item);
tmp_crazyfly_zone_item->setRect(tmp_crazyfly_zone_item->rect().normalized());
addCrazyFlyZoneToVector(tmp_crazyfly_zone_item);
std::string str = std::to_string(tmp_crazyfly_zone_item->getIndex() + 1);
tmp_crazyfly_zone_item->setLabel(str.c_str());
setSelectedCrazyFlyZone(crazyfly_zones.size() - 1); //select just created rectangle
}
void myGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
......@@ -413,7 +424,6 @@ void myGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
tmp_crazyfly_zone_item->setRect(tmp_crazyfly_zone_item->rect().normalized());
addCrazyFlyZoneToVector(tmp_crazyfly_zone_item);
// TODO: set first available number, not size of vector. Index + 1
std::string str = std::to_string(tmp_crazyfly_zone_item->getIndex() + 1);
tmp_crazyfly_zone_item->setLabel(str.c_str());
setSelectedCrazyFlyZone(crazyfly_zones.size() - 1); //select just created rectangle
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment