Apply button
This commit is contained in:
parent
968d55aafa
commit
c6dd35f03d
2 changed files with 39 additions and 1 deletions
|
@ -8,6 +8,7 @@ class QStackedWidget;
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QListWidgetItem;
|
class QListWidgetItem;
|
||||||
class QDataWidgetMapper;
|
class QDataWidgetMapper;
|
||||||
|
class QPushButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
class OptionsModel;
|
class OptionsModel;
|
||||||
class MainOptionsPage;
|
class MainOptionsPage;
|
||||||
|
@ -24,12 +25,18 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
|
private slots:
|
||||||
|
void okClicked();
|
||||||
|
void cancelClicked();
|
||||||
|
void applyClicked();
|
||||||
|
void enableApply();
|
||||||
private:
|
private:
|
||||||
QListWidget *contents_widget;
|
QListWidget *contents_widget;
|
||||||
QStackedWidget *pages_widget;
|
QStackedWidget *pages_widget;
|
||||||
MainOptionsPage *main_options_page;
|
MainOptionsPage *main_options_page;
|
||||||
OptionsModel *model;
|
OptionsModel *model;
|
||||||
QDataWidgetMapper *mapper;
|
QDataWidgetMapper *mapper;
|
||||||
|
QPushButton *apply_button;
|
||||||
|
|
||||||
void setupMainPage();
|
void setupMainPage();
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QDataWidgetMapper>
|
#include <QDataWidgetMapper>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
OptionsDialog::OptionsDialog(QWidget *parent):
|
OptionsDialog::OptionsDialog(QWidget *parent):
|
||||||
QDialog(parent), contents_widget(0), pages_widget(0),
|
QDialog(parent), contents_widget(0), pages_widget(0),
|
||||||
|
@ -39,7 +40,8 @@ OptionsDialog::OptionsDialog(QWidget *parent):
|
||||||
buttons->addWidget(ok_button);
|
buttons->addWidget(ok_button);
|
||||||
QPushButton *cancel_button = new QPushButton(tr("Cancel"));
|
QPushButton *cancel_button = new QPushButton(tr("Cancel"));
|
||||||
buttons->addWidget(cancel_button);
|
buttons->addWidget(cancel_button);
|
||||||
QPushButton *apply_button = new QPushButton(tr("Apply"));
|
apply_button = new QPushButton(tr("Apply"));
|
||||||
|
apply_button->setEnabled(false);
|
||||||
buttons->addWidget(apply_button);
|
buttons->addWidget(apply_button);
|
||||||
|
|
||||||
layout->addLayout(buttons);
|
layout->addLayout(buttons);
|
||||||
|
@ -47,9 +49,16 @@ OptionsDialog::OptionsDialog(QWidget *parent):
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
setWindowTitle(tr("Options"));
|
setWindowTitle(tr("Options"));
|
||||||
|
|
||||||
|
/* Widget-to-option mapper */
|
||||||
mapper = new QDataWidgetMapper();
|
mapper = new QDataWidgetMapper();
|
||||||
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
||||||
mapper->setOrientation(Qt::Vertical);
|
mapper->setOrientation(Qt::Vertical);
|
||||||
|
connect(mapper->itemDelegate(), SIGNAL(commitData(QWidget*)), this, SLOT(enableApply()));
|
||||||
|
|
||||||
|
/* Event bindings */
|
||||||
|
connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked()));
|
||||||
|
connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
||||||
|
connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionsDialog::setModel(OptionsModel *model)
|
void OptionsDialog::setModel(OptionsModel *model)
|
||||||
|
@ -70,3 +79,25 @@ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previo
|
||||||
pages_widget->setCurrentIndex(contents_widget->row(current));
|
pages_widget->setCurrentIndex(contents_widget->row(current));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::okClicked()
|
||||||
|
{
|
||||||
|
mapper->submit();
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::cancelClicked()
|
||||||
|
{
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::applyClicked()
|
||||||
|
{
|
||||||
|
mapper->submit();
|
||||||
|
apply_button->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::enableApply()
|
||||||
|
{
|
||||||
|
apply_button->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue