| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | # include <QListWidgetItem> |
| | # include <QList> |
| | # include <QPushButton> |
| |
|
| | #include <Base/Console.h> |
| |
|
| | #include "DlgPageChooser.h" |
| | #include "ui_DlgPageChooser.h" |
| |
|
| |
|
| | FC_LOG_LEVEL_INIT("Gui", true, true) |
| |
|
| | using namespace TechDrawGui; |
| |
|
| | |
| |
|
| | DlgPageChooser::DlgPageChooser( |
| | const std::vector<std::string>& labels, |
| | const std::vector<std::string>& names, |
| | QWidget* parent, Qt::WindowFlags fl) |
| | : QDialog(parent, fl), ui(new Ui_DlgPageChooser) |
| | { |
| | ui->setupUi(this); |
| | ui->lwPages->setSortingEnabled(true); |
| |
|
| | fillList(labels, names); |
| |
|
| | 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); |
| | } |
| |
|
| | |
| | |
| | |
| | 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) |
| | { |
| | size_t labelCount = labels.size(); |
| | size_t i = 0; |
| | for (; i < labelCount; i++) { |
| | 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); |
| | } |
| | } |
| |
|
| | std::string DlgPageChooser::getSelection() const |
| | { |
| | QList<QListWidgetItem*> sels = ui->lwPages->selectedItems(); |
| | if (!sels.empty()) { |
| | QListWidgetItem* item = sels.front(); |
| | return item->data(Qt::UserRole).toByteArray().constData(); |
| | } |
| | return {}; |
| | } |
| |
|
| |
|
| | void DlgPageChooser::accept() { |
| | if (ui->lwPages->selectedItems().empty()) { |
| | Base::Console().message("Page Chooser: no page was selected\n"); |
| | } |
| | QDialog::accept(); |
| | } |
| |
|
| | void DlgPageChooser::reject() { |
| | QDialog::reject(); |
| | } |
| |
|
| | |
| | #include "moc_DlgPageChooser.cpp" |
| |
|