-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from gergondet/topic/SupportTableElement
[GUI] Support Table element
- Loading branch information
Showing
5 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2016-2020 CNRS-UM LIRMM, CNRS-AIST JRL | ||
*/ | ||
|
||
#include "TableWidget.h" | ||
|
||
namespace mc_rtc_rviz | ||
{ | ||
|
||
TableWidget::TableWidget(const ClientWidgetParam & params) : ClientWidget(params) | ||
{ | ||
layout_ = new QHBoxLayout(this); | ||
table_ = new QTableWidget(); | ||
table_->verticalHeader()->hide(); | ||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) | ||
table_->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | ||
#else | ||
table_->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | ||
#endif | ||
layout_->addWidget(table_); | ||
} | ||
|
||
void TableWidget::header(const std::vector<std::string> & header) | ||
{ | ||
rowCount_ = 0; | ||
if(header_ == header) | ||
{ | ||
return; | ||
} | ||
header_ = header; | ||
table_->setColumnCount(header_.size()); | ||
for(size_t j = 0; j < header_.size(); ++j) | ||
{ | ||
auto item = table_->horizontalHeaderItem(j); | ||
if(!item) | ||
{ | ||
item = new QTableWidgetItem(); | ||
table_->setHorizontalHeaderItem(j, item); | ||
} | ||
item->setText(header_[j].c_str()); | ||
} | ||
} | ||
|
||
void TableWidget::row(const std::vector<std::string> & data) | ||
{ | ||
for(size_t j = 0; j < data.size(); ++j) | ||
{ | ||
updateItem(rowCount_, j, data[j]); | ||
} | ||
rowCount_ += 1; | ||
} | ||
|
||
void TableWidget::finalize() | ||
{ | ||
while(table_->rowCount() > rowCount_) | ||
{ | ||
table_->removeRow(table_->rowCount() - 1); | ||
} | ||
} | ||
|
||
void TableWidget::updateItem(int row, int column, const std::string & text) | ||
{ | ||
if(table_->rowCount() < row + 1) | ||
{ | ||
table_->setRowCount(row + 1); | ||
} | ||
if(table_->columnCount() < column + 1) | ||
{ | ||
table_->setColumnCount(column + 1); | ||
} | ||
auto item = dynamic_cast<QLabel *>(table_->cellWidget(row, column)); | ||
if(!item) | ||
{ | ||
item = new QLabel(); | ||
table_->setCellWidget(row, column, item); | ||
} | ||
item->setText(text.c_str()); | ||
} | ||
|
||
} // namespace mc_rtc_rviz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2016-2020 CNRS-UM LIRMM, CNRS-AIST JRL | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ClientWidget.h" | ||
|
||
namespace mc_rtc_rviz | ||
{ | ||
|
||
struct TableWidget : public ClientWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
TableWidget(const ClientWidgetParam & params); | ||
|
||
void header(const std::vector<std::string> & header); | ||
|
||
void row(const std::vector<std::string> & data); | ||
|
||
void finalize(); | ||
|
||
private: | ||
std::vector<std::string> header_ = {}; | ||
int rowCount_ = 0; | ||
QHBoxLayout * layout_ = nullptr; | ||
QTableWidget * table_ = nullptr; | ||
|
||
void updateItem(int row, int column, const std::string & text); | ||
}; | ||
|
||
} // namespace mc_rtc_rviz |