[TD]fix page selection from list
This commit is contained in:
@@ -20,10 +20,11 @@
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#include "PreCompiled.h" //NOLINT
|
||||
#ifndef _PreComp_
|
||||
# include <QListWidgetItem>
|
||||
# include <QList>
|
||||
# include <QPushButton>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h> // for FC_LOG_LEVEL_INIT
|
||||
@@ -32,15 +33,15 @@
|
||||
#include "ui_DlgPageChooser.h"
|
||||
|
||||
|
||||
FC_LOG_LEVEL_INIT("Gui", true, true)
|
||||
FC_LOG_LEVEL_INIT("Gui", true, true) //NOLINT
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
/* TRANSLATOR Gui::DlgPageChooser */
|
||||
|
||||
DlgPageChooser::DlgPageChooser(
|
||||
const std::vector<std::string> labels,
|
||||
const std::vector<std::string> names,
|
||||
const std::vector<std::string>& labels,
|
||||
const std::vector<std::string>& names,
|
||||
QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl), ui(new Ui_DlgPageChooser)
|
||||
{
|
||||
@@ -51,6 +52,9 @@ DlgPageChooser::DlgPageChooser(
|
||||
|
||||
connect(ui->bbButtons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(ui->bbButtons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
connect(ui->lwPages, &QListWidget::itemSelectionChanged, this, &DlgPageChooser::slotChangedSelection);
|
||||
auto acceptButton = ui->bbButtons->button(QDialogButtonBox::Ok);
|
||||
acceptButton->setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,19 +66,26 @@ DlgPageChooser::~DlgPageChooser()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DlgPageChooser::slotChangedSelection()
|
||||
{
|
||||
auto acceptButton = ui->bbButtons->button(QDialogButtonBox::Ok);
|
||||
if (ui->lwPages->selectedItems().empty()) {
|
||||
acceptButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
acceptButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void DlgPageChooser::fillList(std::vector<std::string> labels, std::vector<std::string> names)
|
||||
{
|
||||
QListWidgetItem* item;
|
||||
QString qLabel;
|
||||
QString qName;
|
||||
QString qText;
|
||||
int labelCount = labels.size();
|
||||
int i = 0;
|
||||
size_t labelCount = labels.size();
|
||||
size_t i = 0;
|
||||
for (; i < labelCount; i++) {
|
||||
qLabel = QString::fromStdString(labels[i]);
|
||||
qName = QString::fromStdString(names[i]);
|
||||
qText = QStringLiteral("%1 (%2)").arg(qLabel, qName);
|
||||
item = new QListWidgetItem(qText, ui->lwPages);
|
||||
auto qLabel = QString::fromStdString(labels[i]);
|
||||
auto qName = QString::fromStdString(names[i]);
|
||||
auto qText = QStringLiteral("%1 (%2)").arg(qLabel, qName);
|
||||
auto* item = new QListWidgetItem(qText, ui->lwPages);
|
||||
item->setData(Qt::UserRole, qName);
|
||||
}
|
||||
}
|
||||
@@ -86,11 +97,14 @@ std::string DlgPageChooser::getSelection() const
|
||||
QListWidgetItem* item = sels.front();
|
||||
return item->data(Qt::UserRole).toByteArray().constData();
|
||||
}
|
||||
return std::string();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void DlgPageChooser::accept() {
|
||||
if (ui->lwPages->selectedItems().empty()) {
|
||||
Base::Console().Message("Page Chooser: no page was selected\n");
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
@@ -98,4 +112,5 @@ void DlgPageChooser::reject() {
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
#include "moc_DlgPageChooser.cpp"
|
||||
|
||||
@@ -29,13 +29,16 @@
|
||||
namespace TechDrawGui {
|
||||
|
||||
class Ui_DlgPageChooser;
|
||||
|
||||
//NOLINTBEGIN
|
||||
class TechDrawGuiExport DlgPageChooser : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
//NOLINTEND
|
||||
|
||||
public:
|
||||
DlgPageChooser(const std::vector<std::string> labels,
|
||||
const std::vector<std::string> names,
|
||||
DlgPageChooser(const std::vector<std::string>& labels,
|
||||
const std::vector<std::string>& names,
|
||||
QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
|
||||
~DlgPageChooser() override;
|
||||
|
||||
@@ -43,7 +46,8 @@ public:
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
public Q_SLOTS:
|
||||
void slotChangedSelection();
|
||||
|
||||
private:
|
||||
void fillList(std::vector<std::string> labels, std::vector<std::string> names);
|
||||
|
||||
Reference in New Issue
Block a user