Commit 2a5a53e3 authored by roangel's avatar roangel
Browse files

removal of links implemented. Now the headers are missing?

parent 078e3e0a
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.0.2, 2017-05-23T19:29:03. -->
<!-- Written by QtCreator 4.0.2, 2017-05-24T16:08:15. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -75,11 +75,19 @@ void CFLinker::addNewRow(int student_id, std::string crazyfly_name, int cf_zone_
{
m_ui->table_links->insertRow(m_ui->table_links->rowCount());
QString str_id = QString::number(student_id);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 0, new QTableWidgetItem(str_id));
QTableWidgetItem *item_id = new QTableWidgetItem(str_id);
item_id->setFlags(item_id->flags() & ~Qt::ItemIsEditable);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 0, item_id);
QString str_cf_name = QString::fromStdString(crazyfly_name);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 1, new QTableWidgetItem(str_cf_name));
QTableWidgetItem *item_cf = new QTableWidgetItem(str_cf_name);
item_cf->setFlags(item_cf->flags() & ~Qt::ItemIsEditable);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 1, item_cf);
QString str_cf_zone_index = QString("CrazyFlyZone ").append(QString::number(cf_zone_index + 1));
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, new QTableWidgetItem(str_cf_zone_index));
QTableWidgetItem *item_cf_zone = new QTableWidgetItem(str_cf_zone_index);
item_cf_zone->setFlags(item_cf_zone->flags() & ~Qt::ItemIsEditable);
m_ui->table_links->setItem(m_ui->table_links->rowCount() - 1, 2, item_cf_zone);
}
void CFLinker::link()
......@@ -116,5 +124,37 @@ void CFLinker::link()
void CFLinker::unlink()
{
QModelIndexList selection = m_ui->table_links->selectionModel()->selectedRows();
// first, get an ordered from greater to lesser vector of indexes of selected rows
std::vector<int> ordered_row_indexes;
for(int i = selection.count() - 1; i >= 0; i--) // fill vector first
{
QModelIndex index = selection.at(i);
ordered_row_indexes.push_back(index.row());
}
// sort using a standard library compare function object, greater to lesser
std::sort(ordered_row_indexes.begin(), ordered_row_indexes.end(), std::greater<int>());
// now, unlink them in data structure and graphically removing rows from the table
for(int i = 0; i < ordered_row_indexes.size(); i++)
{
// TODO: unset linked status in its corresponding objects
// remove them from links vector. We will look for student as unique key.. Maybe in a future the CF is the unique key?
int student_id = m_ui->table_links->item(ordered_row_indexes[i], 0)->text().toInt(); // 0: student ID
for(int i = 0; i < links.size(); i++)
{
if(links[i].student_id == student_id)
{
links.erase(links.begin() + i);
break;
}
}
// remove them graphically
m_ui->table_links->removeRow(ordered_row_indexes[i]);
}
}
......@@ -117,15 +117,12 @@ void MainGUIWindow::_init()
// initialize table_links
ui->table_links->setColumnCount(3);
QStringList horizontal_header;
horizontal_header << "Student ID" << "CrazyFly" << "CrazyFly Zone";
ui->table_links->setHorizontalHeaderLabels(horizontal_header);
QFont fnt;
fnt.setPointSize(7);
ui->table_links->horizontalHeader()->setFont(fnt);
ui->table_links->horizontalHeader()->setDefaultSectionSize(90);
// ui->table_links->verticalHeader()->setDefaultSectionSize(20);
ui->table_links->verticalHeader()->setDefaultSectionSize(20);
const int rowCount = ui->table_links->rowCount();
......@@ -138,7 +135,10 @@ void MainGUIWindow::_init()
selectedItem->setFont(fnt);
}
}
ui->table_links->setSelectionBehavior(QAbstractItemView::SelectRows);
// ui->table_links->setSelectionBehavior(QAbstractItemView::SelectRows);
QStringList horizontal_header;
horizontal_header << "Student ID" << "CrazyFly" << "CrazyFly Zone";
ui->table_links->setHorizontalHeaderLabels(horizontal_header);
// scene
scene = new myGraphicsScene(ui->frame_drawing);
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>866</width>
<height>587</height>
<width>884</width>
<height>716</height>
</rect>
</property>
<property name="windowTitle">
......@@ -233,6 +233,43 @@
<zorder>pushButton_fitAll</zorder>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QFrame" name="frame_3">
<property name="sizePolicy">
......@@ -344,13 +381,6 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="refresh_student_ids_button">
<property name="text">
<string>Refresh IDs</string>
</property>
</widget>
</item>
<item row="16" column="1" colspan="2">
<widget class="QTableWidget" name="table_links">
<property name="minimumSize">
......@@ -436,6 +466,13 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="refresh_student_ids_button">
<property name="text">
<string>Refresh IDs</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
......@@ -443,43 +480,6 @@
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
......@@ -487,7 +487,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>866</width>
<width>884</width>
<height>19</height>
</rect>
</property>
......
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