selectlistdialog.h
Go to the documentation of this file.
1 #ifndef SELECT_FROM_LIST_DIALOG_H
2 #define SELECT_FROM_LIST_DIALOG_H
3 
4 #include <QDialog>
5 #include <deque>
6 #include "ui_selectlistdialog.h"
7 
8 namespace Ui
9 {
11 }
12 
13 class SelectFromListDialog : public QDialog
14 {
15  Q_OBJECT
16 
17 public:
18  explicit SelectFromListDialog(const std::deque<std::string>& fields,
19  bool single_selection = true, QWidget* parent = 0);
21 
22  std::vector<int> getSelectedRowNumber() const;
23 
24 private slots:
25  void on_buttonBox_accepted();
26 
27  void on_listFieldsWidget_currentRowChanged(int currentRow);
28 
29  void on_listFieldsWidget_doubleClicked(const QModelIndex& index);
30 
32 
33  void on_listFieldsWidget_clicked(const QModelIndex& index);
34 
35 private:
36  Ui::SelectXAxisDialog* ui;
37  std::vector<int> _selected_row_number;
39 };
40 
41 //-----------------------------------------------
42 inline SelectFromListDialog::SelectFromListDialog(const std::deque<std::string>& fields,
43  bool single_selection, QWidget* parent)
44  : QDialog(parent), ui(new Ui::SelectXAxisDialog), _single_selection(single_selection)
45 {
46  auto flags = this->windowFlags();
47  this->setWindowFlags(flags | Qt::WindowStaysOnTopHint);
48 
49  ui->setupUi(this);
50 
51  if (!_single_selection)
52  {
53  ui->listFieldsWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
54  }
55  else
56  {
57  ui->pushButtonSelectAll->hide();
58  }
59 
60  // if there is only one item in the list, select it by default
61  for (int i = 0; i < fields.size(); i++)
62  {
63  auto item = new QListWidgetItem(QString::fromStdString(fields[i]));
64  ui->listFieldsWidget->addItem(item);
65 
66  if (fields.size() == 1)
67  {
68  item->setSelected(true);
69  }
70  }
71 }
72 
74 {
75  delete ui;
76 }
77 
78 inline std::vector<int> SelectFromListDialog::getSelectedRowNumber() const
79 {
80  return _selected_row_number;
81 }
82 
83 inline void SelectFromListDialog::on_listFieldsWidget_clicked(const QModelIndex& index)
84 {
85  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
86  ui->buttonBox->setEnabled(indexes.empty() == false);
87 }
88 
90 {
91  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
92 
93  foreach (QModelIndex index, indexes)
94  {
95  _selected_row_number.push_back(index.row());
96  }
97 }
98 
100 {
101  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
102  ui->buttonBox->setEnabled(indexes.empty() == false);
103 }
104 
106 {
107  if (_single_selection)
108  {
109  _selected_row_number.push_back(ui->listFieldsWidget->currentRow());
110  this->accept();
111  }
112 }
113 
115 {
116  for (int i = 0; i < ui->listFieldsWidget->count(); i++)
117  {
118  _selected_row_number.push_back(i);
119  }
120  this->accept();
121 }
122 
123 #endif // SELECTXAXISDIALOG_H
SelectFromListDialog::on_listFieldsWidget_currentRowChanged
void on_listFieldsWidget_currentRowChanged(int currentRow)
Definition: selectlistdialog.h:99
SelectFromListDialog::ui
Ui::SelectXAxisDialog * ui
Definition: selectlistdialog.h:36
SelectFromListDialog::SelectFromListDialog
SelectFromListDialog(const std::deque< std::string > &fields, bool single_selection=true, QWidget *parent=0)
Definition: selectlistdialog.h:42
SelectFromListDialog::on_buttonBox_accepted
void on_buttonBox_accepted()
Definition: selectlistdialog.h:89
SelectFromListDialog::_selected_row_number
std::vector< int > _selected_row_number
Definition: selectlistdialog.h:37
Ui
Definition: cheatsheet_dialog.h:6
SelectFromListDialog::on_pushButtonSelectAll_pressed
void on_pushButtonSelectAll_pressed()
Definition: selectlistdialog.h:114
SelectFromListDialog::_single_selection
bool _single_selection
Definition: selectlistdialog.h:38
SelectFromListDialog
Definition: selectlistdialog.h:13
SelectFromListDialog::on_listFieldsWidget_clicked
void on_listFieldsWidget_clicked(const QModelIndex &index)
Definition: selectlistdialog.h:83
SelectFromListDialog::~SelectFromListDialog
~SelectFromListDialog()
Definition: selectlistdialog.h:73
SelectFromListDialog::on_listFieldsWidget_doubleClicked
void on_listFieldsWidget_doubleClicked(const QModelIndex &index)
Definition: selectlistdialog.h:105
SelectFromListDialog::getSelectedRowNumber
std::vector< int > getSelectedRowNumber() const
Definition: selectlistdialog.h:78


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46