10 #include "ui_customViewpointButtonDlg.h"
20 #ifdef USE_PCL_BACKEND
26 #include <QFileDialog>
27 #include <QToolButton>
40 QPointer<QLabel> IndexLabel;
41 QPointer<QLineEdit> ToolTipEdit;
42 QPointer<QPushButton> AssignButton;
43 QPointer<QToolButton> DeleteButton;
46 QPointer<::ecvCustomViewpointButtonDlg> Parent;
55 if (this->Rows.size() == rows) {
60 this->add->setEnabled(
64 for (
int cc = this->Rows.size() - 1; cc >= rows; --cc) {
65 auto& arow = this->Rows[cc];
66 this->gridLayout->removeWidget(arow.IndexLabel);
67 this->gridLayout->removeWidget(arow.ToolTipEdit);
68 this->gridLayout->removeWidget(arow.AssignButton);
69 if (arow.DeleteButton) {
70 this->gridLayout->removeWidget(arow.DeleteButton);
72 delete arow.IndexLabel;
73 delete arow.ToolTipEdit;
74 delete arow.AssignButton;
75 delete arow.DeleteButton;
76 this->Rows.pop_back();
80 for (
int cc = this->Rows.size(); cc < rows; ++cc) {
82 arow.IndexLabel =
new QLabel(QString::number(cc + 1), this->Parent);
83 arow.IndexLabel->setAlignment(Qt::AlignCenter);
84 arow.ToolTipEdit =
new QLineEdit(this->Parent);
85 arow.ToolTipEdit->setToolTip(
86 "This text will be set to the buttons tool tip.");
87 arow.ToolTipEdit->setText(
89 arow.ToolTipEdit->setObjectName(QString(
"toolTip%1").arg(cc));
91 new QPushButton(
"Current Viewpoint", this->Parent);
92 arow.AssignButton->setProperty(
93 "pqCustomViewpointButtonDialog_INDEX", cc);
94 arow.AssignButton->setObjectName(
95 QString(
"currentViewpoint%1").arg(cc));
96 this->Parent->connect(arow.AssignButton, SIGNAL(clicked()),
97 SLOT(assignCurrentViewpoint()));
98 this->gridLayout->addWidget(arow.IndexLabel, cc + 1, 0);
99 this->gridLayout->addWidget(arow.ToolTipEdit, cc + 1, 1);
100 this->gridLayout->addWidget(arow.AssignButton, cc + 1, 2);
102 arow.DeleteButton =
new QToolButton(this->Parent);
103 arow.DeleteButton->setObjectName(QString(
"delete%1").arg(cc));
104 arow.DeleteButton->setIcon(
105 QIcon(
":/Resources/images/ecvdelete.png"));
106 arow.DeleteButton->setProperty(
107 "pqCustomViewpointButtonDialog_INDEX", cc);
108 this->gridLayout->addWidget(arow.DeleteButton, cc + 1, 3);
109 this->Parent->connect(arow.DeleteButton, SIGNAL(clicked()),
112 this->Rows.push_back(arow);
119 assert(this->Rows.size() == txts.size());
120 for (
int cc = 0, max = this->Rows.size(); cc < max; ++cc) {
121 this->Rows[cc].ToolTipEdit->setText(txts[cc]);
127 for (
const auto& arow : this->Rows) {
128 tips.push_back(arow.ToolTipEdit->text());
134 assert(index >= 0 && index < this->Rows.size());
135 this->Rows[index].ToolTipEdit->setText(txt);
136 this->Rows[index].ToolTipEdit->selectAll();
137 this->Rows[index].ToolTipEdit->setFocus();
141 assert(index >= 0 && index < this->Rows.size());
142 return this->Rows[index].ToolTipEdit->text();
146 assert(index >= 0 && index < this->Rows.size());
147 auto& arow = this->Rows[index];
148 this->gridLayout->removeWidget(arow.IndexLabel);
149 this->gridLayout->removeWidget(arow.ToolTipEdit);
150 this->gridLayout->removeWidget(arow.AssignButton);
151 if (arow.DeleteButton) {
152 this->gridLayout->removeWidget(arow.DeleteButton);
154 delete arow.IndexLabel;
155 delete arow.ToolTipEdit;
156 delete arow.AssignButton;
157 delete arow.DeleteButton;
158 this->Rows.removeAt(index);
161 for (
int cc = index; cc < this->Rows.size(); ++cc) {
162 auto& currentRow = this->Rows[cc];
163 currentRow.IndexLabel->setText(QString::number(cc + 1));
164 currentRow.AssignButton->setProperty(
165 "pqCustomViewpointButtonDialog_INDEX", cc);
166 this->gridLayout->addWidget(currentRow.IndexLabel, cc + 1, 0);
167 this->gridLayout->addWidget(currentRow.ToolTipEdit, cc + 1, 1);
168 this->gridLayout->addWidget(currentRow.AssignButton, cc + 1, 2);
169 if (currentRow.DeleteButton) {
170 currentRow.DeleteButton->setProperty(
171 "pqCustomViewpointButtonDialog_INDEX", cc);
172 this->gridLayout->addWidget(currentRow.DeleteButton, cc + 1, 3);
177 this->add->setEnabled(
200 QString(
"Unnamed Viewpoint");
206 Qt::WindowFlags flags,
207 QStringList& toolTips,
208 QStringList& configs,
210 : QDialog(Parent, flags), ui(nullptr) {
212 this->ui->setupUi(
this);
215 QObject::connect(this->ui->add, SIGNAL(clicked()),
this, SLOT(appendRow()));
216 QObject::connect(this->ui->clearAll, SIGNAL(clicked()),
this,
218 QObject::connect(this->ui->importAll, SIGNAL(clicked()),
this,
219 SLOT(importConfigurations()));
220 QObject::connect(this->ui->exportAll, SIGNAL(clicked()),
this,
221 SLOT(exportConfigurations()));
232 const QStringList& toolTips,
const QStringList& configs) {
233 if (toolTips.size() != configs.size()) {
235 "`setToolTipsAndConfigurations` called with mismatched "
239 int minSize = std::min(toolTips.size(), configs.size());
242 <<
" will be ignored.";
246 QStringList realToolTips = toolTips.mid(0, minSize);
247 QStringList realConfigs = configs.mid(0, minSize);
252 realConfigs.push_back(QString());
262 if (toolTips.length() != this->ui->rowCount()) {
276 const QStringList& configs) {
277 if (configs.length() != this->ui->rowCount()) {
281 this->Configurations = configs;
286 return this->Configurations;
291 const QString& config) {
292 this->CurrentConfiguration = config;
297 return this->CurrentConfiguration;
301 void ecvCustomViewpointButtonDlg::importConfigurations() {
308 QString filters = QString(
"%1 (*%2);;All Files (*.*)")
313 QString currentPath =
317 QStringList selectedFiles = QFileDialog::getOpenFileNames(
318 this, QString(
"Load Custom Viewpoints Configuration"), currentPath,
321 if (selectedFiles.isEmpty())
return;
327 #ifdef USE_PCL_BACKEND
331 "[ecvCustomViewpointButtonDlg::importConfigurations] please use "
332 "pcl as backend and then try again!");
336 QStringList toolTips;
346 void ecvCustomViewpointButtonDlg::exportConfigurations() {
349 QString filters = QString(
"%1 (*%2);;All Files (*.*)")
354 QString currentPath =
360 QString selectedFilename = QFileDialog::getSaveFileName(
361 this, tr(
"Save Custom Viewpoints Configuration"), currentPath,
364 if (selectedFilename.isEmpty()) {
369 QString
filename = selectedFilename;
374 void ecvCustomViewpointButtonDlg::appendRow() {
375 const int numRows = this->ui->
rowCount();
378 #ifdef USE_PCL_BACKEND
382 "[ecvCustomViewpointButtonDlg::importConfigurations] please use "
383 "pcl as backend and then try again!");
387 QString curCameraParam =
389 this->Configurations.push_back(curCameraParam);
393 void ecvCustomViewpointButtonDlg::clearAll() {
398 void ecvCustomViewpointButtonDlg::assignCurrentViewpoint() {
400 if (QObject* asender = this->sender()) {
401 row = asender->property(
"pqCustomViewpointButtonDialog_INDEX").toInt();
404 if (row >= 0 && row < this->ui->
rowCount()) {
405 this->Configurations[row] = this->CurrentConfiguration;
409 row,
"Current Viewpoint " + QString::number(row + 1));
415 void ecvCustomViewpointButtonDlg::deleteRow() {
417 if (QObject* asender = this->sender()) {
418 row = asender->property(
"pqCustomViewpointButtonDialog_INDEX").toInt();
421 if (row >= 0 && row < this->ui->
rowCount()) {
423 this->Configurations.removeAt(row);
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
static const QString CurrentPath()
static const QString SaveFile()
static const QString LoadFile()
static QVariant getValue(const QString §ion, const QString &key, const QVariant &defaultValue=QVariant())
QString defaultDocPath()
Shortcut for getting the documents location path.