File indexing completed on 2022-12-06 21:12:08

0001 /***************************************************************************
0002                        numberdialog.h  -  description
0003                              -------------------
0004     begin                : The May 24 2007
0005     copyright            : (C) 2007 by Dominik Seichter
0006     email                : domseichter@web.de
0007 ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "numberdialog.h"
0019 
0020 #include <QDialogButtonBox>
0021 #include <QVBoxLayout>
0022 
0023 NumberDialog::NumberDialog(int start, int step, bool reset, QList<int> skip, QWidget *parent)
0024     : QDialog(parent)
0025 {
0026     QVBoxLayout *layout = new QVBoxLayout(this);
0027     QWidget     *widget = new QWidget(this);
0028 
0029     m_widget.setupUi(widget);
0030     m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
0031 
0032     layout->addWidget(widget);
0033     layout->addWidget(m_buttons);
0034 
0035     connect(m_buttons, &QDialogButtonBox::accepted,
0036             this, &NumberDialog::accept);
0037     connect(m_buttons, &QDialogButtonBox::rejected,
0038             this, &NumberDialog::reject);
0039 
0040     connect(m_widget.buttonAdd, &QPushButton::clicked,
0041             this, &NumberDialog::slotAddNumber);
0042     connect(m_widget.buttonRemove, &QPushButton::clicked, this,
0043             &NumberDialog::slotRemoveNumber);
0044     connect(m_widget.listSkip, &QListWidget::itemSelectionChanged,
0045             this, &NumberDialog::slotEnableControls);
0046     m_widget.spinStart->setValue(start);
0047     m_widget.spinStep->setValue(step);
0048     m_widget.checkReset->setChecked(reset);
0049     m_widget.listSkip->setSortingEnabled(true);   // TODO: sort numeric
0050 
0051     QList<int>::ConstIterator it = skip.constBegin();
0052     while (it != skip.constEnd()) {
0053         m_widget.listSkip->addItem(QString::number(*it));
0054         ++it;
0055     }
0056 }
0057 
0058 QList<int> NumberDialog::skipNumbers() const
0059 {
0060     QList<int> list;
0061 
0062     for (int i = 0; i < m_widget.listSkip->count(); i++) {
0063         QListWidgetItem *item = m_widget.listSkip->item(i);
0064         list.append(item->data(Qt::DisplayRole).toInt());
0065 
0066     }
0067     return list;
0068 }
0069 
0070 void NumberDialog::slotEnableControls()
0071 {
0072     QList<QListWidgetItem *> selected = m_widget.listSkip->selectedItems();
0073     m_widget.buttonRemove->setEnabled(selected.size());
0074 }
0075 
0076 void NumberDialog::slotAddNumber()
0077 {
0078     m_widget.listSkip->addItem(QString::number(m_widget.spinNumber->value()));
0079 }
0080 
0081 void NumberDialog::slotRemoveNumber()
0082 {
0083     delete m_widget.listSkip->takeItem(m_widget.listSkip->currentRow());
0084 }