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 {
10 }
11 
12 class SelectFromListDialog : public QDialog
13 {
14  Q_OBJECT
15 
16 public:
17  explicit SelectFromListDialog(const std::deque<std::string> &fields, bool single_selection = true, QWidget *parent = 0);
19 
20  std::vector<int> getSelectedRowNumber() const;
21 
22 private slots:
23  void on_buttonBox_accepted();
24 
25  void on_listFieldsWidget_currentRowChanged(int currentRow);
26 
27  void on_listFieldsWidget_doubleClicked(const QModelIndex &index);
28 
29  void on_pushButtonSelectAll_pressed();
30 
31  void on_listFieldsWidget_clicked(const QModelIndex &index);
32 
33 private:
34  Ui::SelectXAxisDialog *ui;
35  std::vector<int> _selected_row_number;
37 };
38 
39 
40 //-----------------------------------------------
41 inline SelectFromListDialog::SelectFromListDialog(const std::deque<std::string>& fields, bool single_selection, QWidget *parent) :
42  QDialog(parent),
43  ui(new Ui::SelectXAxisDialog),
44  _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  ui->listFieldsWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
53  }
54  else{
55  ui->pushButtonSelectAll->hide();
56  }
57 
58  // if there is only one item in the list, select it by default
59  for (int i=0; i< fields.size(); i++)
60  {
61  auto item = new QListWidgetItem( QString::fromStdString(fields[i]) );
62  ui->listFieldsWidget->addItem( item );
63 
64  if( fields.size() == 1){
65  item->setSelected(true);
66  }
67  }
68 }
69 
71 {
72  delete ui;
73 }
74 
75 inline std::vector<int> SelectFromListDialog::getSelectedRowNumber() const
76 {
77  return _selected_row_number;
78 }
79 
80 inline void SelectFromListDialog::on_listFieldsWidget_clicked(const QModelIndex &index)
81 {
82  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
83  ui->buttonBox->setEnabled( indexes.empty() == false );
84 }
85 
87 {
88  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
89 
90  foreach(QModelIndex index, indexes)
91  {
92  _selected_row_number.push_back(index.row());
93  }
94 }
95 
97 {
98  QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
99  ui->buttonBox->setEnabled( indexes.empty() == false );
100 }
101 
103 {
104  if( _single_selection ) {
105  _selected_row_number.push_back( ui->listFieldsWidget->currentRow() );
106  this->accept();
107  }
108 }
109 
111 {
112  for (int i=0; i< ui->listFieldsWidget->count(); i++)
113  {
114  _selected_row_number.push_back(i);
115  }
116  this->accept();
117 }
118 
119 #endif // SELECTXAXISDIALOG_H
SelectFromListDialog(const std::deque< std::string > &fields, bool single_selection=true, QWidget *parent=0)
Ui::SelectXAxisDialog * ui
std::vector< int > getSelectedRowNumber() const
void on_listFieldsWidget_doubleClicked(const QModelIndex &index)
void on_listFieldsWidget_currentRowChanged(int currentRow)
std::vector< int > _selected_row_number
int i
void on_listFieldsWidget_clicked(const QModelIndex &index)
int flags


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18