LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / config / channelform.cpp
bloba15a5f71310b31da2edbe3281d67996d9968fd9f
1 #include "channelform.h"
3 #include <QGridLayout>
6 ChannelForm::ChannelForm(const int index, QWidget *parent) : ConfigTaskWidget(parent), m_index(index)
7 {}
9 ChannelForm::~ChannelForm()
12 int ChannelForm::index() const
14 return m_index;
17 void ChannelForm::moveTo(QGridLayout &dstLayout)
19 QGridLayout *srcLayout = dynamic_cast<QGridLayout *>(layout());
21 Q_ASSERT(srcLayout);
23 // if we are the first row to be inserted then show the legend
24 bool showLegend = (dstLayout.rowCount() == 1);
26 if (showLegend) {
27 // move legend row to target grid layout
28 moveRow(0, *srcLayout, dstLayout);
29 } else {
30 removeRow(0, *srcLayout);
33 // move field row to target grid layout
34 moveRow(1, *srcLayout, dstLayout);
36 // this form is now empty so hide it
37 setVisible(false);
40 void ChannelForm::moveRow(int row, QGridLayout &srcLayout, QGridLayout &dstLayout)
42 int dstRow = dstLayout.rowCount();
44 for (int col = 0; col < srcLayout.columnCount(); col++) {
45 QLayoutItem *item = srcLayout.itemAtPosition(row, col);
46 if (!item) {
47 continue;
49 QWidget *widget = item->widget();
50 if (widget) {
51 dstLayout.addWidget(widget, dstRow, col);
52 continue;
54 // TODO handle item of type QLayout
58 void ChannelForm::removeRow(int row, QGridLayout &layout)
60 for (int col = 0; col < layout.columnCount(); col++) {
61 QLayoutItem *item = layout.itemAtPosition(row, col);
62 if (!item) {
63 continue;
65 QWidget *widget = item->widget();
66 if (widget) {
67 layout.removeWidget(widget);
68 delete widget;
69 continue;
71 // TODO handle item of type QLayout