selectlistdialog.h
Go to the documentation of this file.
00001 #ifndef SELECT_FROM_LIST_DIALOG_H
00002 #define SELECT_FROM_LIST_DIALOG_H
00003 
00004 #include <QDialog>
00005 #include "ui_selectlistdialog.h"
00006 
00007 namespace Ui {
00008 class SelectFromListDialog;
00009 }
00010 
00011 class SelectFromListDialog : public QDialog
00012 {
00013     Q_OBJECT
00014 
00015 public:
00016     explicit SelectFromListDialog(QStringList* fields, bool single_selection = true, QWidget *parent = 0);
00017     ~SelectFromListDialog();
00018 
00019     std::vector<int> getSelectedRowNumber() const;
00020 
00021 private slots:
00022     void on_buttonBox_accepted();
00023 
00024     void on_listFieldsWidget_currentRowChanged(int currentRow);
00025 
00026     void on_listFieldsWidget_doubleClicked(const QModelIndex &index);
00027 
00028     void on_pushButtonSelectAll_pressed();
00029 
00030     void on_listFieldsWidget_clicked(const QModelIndex &index);
00031 
00032 private:
00033     Ui::SelectXAxisDialog *ui;
00034     std::vector<int> _selected_row_number;
00035     bool _single_selection;
00036 };
00037 
00038 
00039 //-----------------------------------------------
00040 inline SelectFromListDialog::SelectFromListDialog(QStringList *fields, bool single_selection, QWidget *parent) :
00041     QDialog(parent),
00042     ui(new Ui::SelectXAxisDialog),
00043     _single_selection( single_selection )
00044 {
00045     auto flags = this->windowFlags();
00046     this->setWindowFlags( flags | Qt::WindowStaysOnTopHint);
00047 
00048     ui->setupUi(this);
00049 
00050     if( ! _single_selection) {
00051         ui->listFieldsWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
00052     }
00053     else{
00054         ui->pushButtonSelectAll->hide();
00055     }
00056 
00057     // if there is only one item in the list, select it by default
00058     for (int i=0; i< fields->size(); i++)
00059     {
00060       auto item = new QListWidgetItem( (*fields)[i] );
00061       ui->listFieldsWidget->addItem( item );
00062 
00063       if( fields->size() == 1){
00064         item->setSelected(true);
00065       }
00066     }
00067 }
00068 
00069 inline SelectFromListDialog::~SelectFromListDialog()
00070 {
00071     delete ui;
00072 }
00073 
00074 inline std::vector<int> SelectFromListDialog::getSelectedRowNumber() const
00075 {
00076     return _selected_row_number;
00077 }
00078 
00079 inline void SelectFromListDialog::on_listFieldsWidget_clicked(const QModelIndex &index)
00080 {
00081     QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
00082     ui->buttonBox->setEnabled( indexes.empty() == false );
00083 }
00084 
00085 inline void SelectFromListDialog::on_buttonBox_accepted()
00086 {
00087     QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
00088 
00089     foreach(QModelIndex index, indexes)
00090     {
00091         _selected_row_number.push_back(index.row());
00092     }
00093 }
00094 
00095 inline void SelectFromListDialog::on_listFieldsWidget_currentRowChanged(int )
00096 {
00097     QModelIndexList indexes = ui->listFieldsWidget->selectionModel()->selectedIndexes();
00098     ui->buttonBox->setEnabled( indexes.empty() == false );
00099 }
00100 
00101 inline void SelectFromListDialog::on_listFieldsWidget_doubleClicked(const QModelIndex &)
00102 {
00103     if( _single_selection ) {
00104         _selected_row_number.push_back( ui->listFieldsWidget->currentRow() );
00105         this->accept();
00106     }
00107 }
00108 
00109 inline void SelectFromListDialog::on_pushButtonSelectAll_pressed()
00110 {
00111     for (int i=0; i< ui->listFieldsWidget->count(); i++)
00112     {
00113         _selected_row_number.push_back(i);
00114     }
00115     this->accept();
00116 }
00117 
00118 #endif // SELECTXAXISDIALOG_H


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:57