From 191e37f29cbd86ff9bc34187d4e62e0cad7be148 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Sun, 6 Dec 2015 19:41:11 +0100 Subject: [PATCH] TableWidget only used if `-D TABLE_LAYOUT=yes` compile option is defined --- companion/src/CMakeLists.txt | 6 +++ companion/src/helpers.cpp | 55 +++++++++++++++++++++ companion/src/helpers.h | 13 ++++- companion/src/modeledit/channels.cpp | 3 +- companion/src/modeledit/customfunctions.cpp | 5 +- companion/src/modeledit/logicalswitches.cpp | 3 +- 6 files changed, 79 insertions(+), 6 deletions(-) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 0cfc9a00de..872add4ed1 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -35,6 +35,12 @@ IF(DEBUG_IMPORT) MESSAGE( STATUS "EEPROM import debugging enabled" ) ENDIF(DEBUG_IMPORT) +OPTION(TABLE_LAYOUT "Use QTableWidget for grid layouts") # Disabled by default +IF(TABLE_LAYOUT) + ADD_DEFINITIONS( -DTABLE_LAYOUT) + MESSAGE( STATUS "Using QTableWidget" ) +ENDIF(TABLE_LAYOUT) + MESSAGE( STATUS "Looking for XercesC " ) FIND_PACKAGE(XercesC) IF ( XERCESC_FOUND ) diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index ace23ceff0..98cb9b73be 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1004,6 +1004,7 @@ QStringList extractLatLon(const QString & position) TableLayout::TableLayout(QWidget * parent, int rowCount, const QStringList & headerLabels) { +#if defined(TABLE_LAYOUT) tableWidget = new QTableWidget(parent); QVBoxLayout * layout = new QVBoxLayout(); layout->addWidget(tableWidget); @@ -1020,19 +1021,73 @@ TableLayout::TableLayout(QWidget * parent, int rowCount, const QStringList & hea tableWidget->setFrameStyle(QFrame::NoFrame | QFrame::Plain); tableWidget->setStyleSheet("QTableWidget {background-color: transparent;}"); tableWidget->setHorizontalHeaderLabels(headerLabels); +#else + gridWidget = new QGridLayout(parent); + + int col = 0; + foreach(QString text, headerLabels) { + QLabel *label = new QLabel(); + label->setFrameShape(QFrame::Panel); + label->setFrameShadow(QFrame::Raised); + label->setMidLineWidth(0); + label->setAlignment(Qt::AlignCenter); + label->setMargin(5); + label->setText(text); + // if (!minimize) + // label->setMinimumWidth(100); + gridWidget->addWidget(label, 0, col++); + } +#endif } void TableLayout::addWidget(int row, int column, QWidget * widget) { +#if defined(TABLE_LAYOUT) QHBoxLayout * layout = new QHBoxLayout(tableWidget); layout->addWidget(widget); addLayout(row, column, layout); +#else + gridWidget->addWidget(widget, row + 1, column); +#endif } void TableLayout::addLayout(int row, int column, QLayout * layout) { +#if defined(TABLE_LAYOUT) layout->setContentsMargins(1, 3, 1, 3); QWidget * containerWidget = new QWidget(tableWidget); containerWidget->setLayout(layout); tableWidget->setCellWidget(row, column, containerWidget); +#else + gridWidget->addLayout(layout, row + 1, column); +#endif +} + +void TableLayout::resizeColumnsToContents() +{ +#if defined(TABLE_LAYOUT) + tableWidget->resizeColumnsToContents(); +#else +#endif +} + +void TableLayout::setColumnWidth(int col, int width) +{ +#if defined(TABLE_LAYOUT) + tableWidget->setColumnWidth(col, width); +#else +#endif +} + +void TableLayout::pushRowsUp(int row) +{ +#if defined(TABLE_LAYOUT) +#else + // Push the rows up + QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ); + gridWidget->addItem(spacer, row, 0); +#endif + // Push rows upward + // addDoubleSpring(gridLayout, 5, num_fsw+1); + } diff --git a/companion/src/helpers.h b/companion/src/helpers.h index db100b84c1..04a204aa7c 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -2,6 +2,8 @@ #define HELPERS_H #include +#include +#include #include "eeprominterface.h" extern const QColor colors[C9X_MAX_CURVES]; @@ -210,9 +212,16 @@ public: void addWidget(int row, int column, QWidget * widget); void addLayout(int row, int column, QLayout * layout); - QTableWidget * getTableWidget() { return tableWidget; }; + void resizeColumnsToContents(); + void setColumnWidth(int col, int width); + void pushRowsUp(int row); + private: - QTableWidget * tableWidget; +#if defined(TABLE_LAYOUT) + QTableWidget * tableWidget; +#else + QGridLayout * gridWidget; +#endif }; #endif // HELPERS_H diff --git a/companion/src/modeledit/channels.cpp b/companion/src/modeledit/channels.cpp index e38bd596ce..3c4a5d899c 100644 --- a/companion/src/modeledit/channels.cpp +++ b/companion/src/modeledit/channels.cpp @@ -169,7 +169,8 @@ Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & genera } disableMouseScrolling(); - tableLayout->getTableWidget()->resizeColumnsToContents(); + tableLayout->resizeColumnsToContents(); + tableLayout->pushRowsUp(firmware->getCapability(Outputs)+1); } Channels::~Channels() diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 4aa5a23123..9b9997da3b 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -196,8 +196,9 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, lock = false; update(); - tableLayout->getTableWidget()->resizeColumnsToContents(); - tableLayout->getTableWidget()->setColumnWidth(3, 300); + tableLayout->resizeColumnsToContents(); + tableLayout->setColumnWidth(3, 300); + tableLayout->pushRowsUp(num_fsw+1); } diff --git a/companion/src/modeledit/logicalswitches.cpp b/companion/src/modeledit/logicalswitches.cpp index 6d7afc4210..f9214739cd 100644 --- a/companion/src/modeledit/logicalswitches.cpp +++ b/companion/src/modeledit/logicalswitches.cpp @@ -126,7 +126,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, disableMouseScrolling(); lock = false; update(); - tableLayout->getTableWidget()->resizeColumnsToContents(); + tableLayout->resizeColumnsToContents(); + tableLayout->pushRowsUp(firmware->getCapability(LogicalSwitches)+1); } LogicalSwitchesPanel::~LogicalSwitchesPanel()