Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kgncpricesourcedlg.cpp
Context not available. | |||||
2 | kgncpricesourcedlg.cpp | 2 | kgncpricesourcedlg.cpp | ||
---|---|---|---|---|---|
3 | ------------------- | 3 | ------------------- | ||
4 | copyright : (C) 2005 by Tony Bloomfield <tonybloom@users.sourceforge.net> | 4 | copyright : (C) 2005 by Tony Bloomfield <tonybloom@users.sourceforge.net> | ||
5 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
5 | 6 | | |||
6 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
7 | 8 | | |||
Context not available. | |||||
23 | #include <QButtonGroup> | 24 | #include <QButtonGroup> | ||
24 | #include <QListWidget> | 25 | #include <QListWidget> | ||
25 | #include <QDialogButtonBox> | 26 | #include <QDialogButtonBox> | ||
26 | #include <QPushButton> | | |||
27 | #include <QVBoxLayout> | | |||
28 | 27 | | |||
29 | // ---------------------------------------------------------------------------- | 28 | // ---------------------------------------------------------------------------- | ||
30 | // KDE Includes | 29 | // KDE Includes | ||
Context not available. | |||||
36 | // Project Includes | 35 | // Project Includes | ||
37 | 36 | | |||
38 | #include "webpricequote.h" | 37 | #include "webpricequote.h" | ||
39 | #include "ui_kgncpricesourcedlgdecl.h" | 38 | #include "ui_kgncpricesourcedlg.h" | ||
40 | 39 | | |||
41 | 40 | class KGncPriceSourceDlgPrivate | |||
42 | class KGncPriceSourceDlgDecl : public QWidget, public Ui::KGncPriceSourceDlgDecl | | |||
43 | { | 41 | { | ||
42 | Q_DISABLE_COPY(KGncPriceSourceDlgPrivate) | ||||
43 | | ||||
44 | public: | 44 | public: | ||
45 | KGncPriceSourceDlgDecl() { | 45 | KGncPriceSourceDlgPrivate() : | ||
46 | setupUi(this); | 46 | ui(new Ui::KGncPriceSourceDlg), | ||
47 | currentButton(0) | ||||
48 | { | ||||
47 | } | 49 | } | ||
48 | }; | | |||
49 | 50 | | |||
51 | ~KGncPriceSourceDlgPrivate() | ||||
52 | { | ||||
53 | delete ui; | ||||
54 | } | ||||
50 | 55 | | |||
51 | struct KGncPriceSourceDlg::Private { | 56 | Ui::KGncPriceSourceDlg *ui; | ||
52 | Private() : currentButton(0), widget(0) {} | | |||
53 | int currentButton; | 57 | int currentButton; | ||
54 | KGncPriceSourceDlgDecl* widget; | | |||
55 | }; | 58 | }; | ||
56 | 59 | | |||
57 | KGncPriceSourceDlg::KGncPriceSourceDlg(QWidget *parent) : QDialog(parent), d(new Private) | | |||
58 | { | | |||
59 | } | | |||
60 | 60 | | |||
61 | KGncPriceSourceDlg::KGncPriceSourceDlg(const QString &stockName, const QString& gncSource, QWidget * parent) : QDialog(parent), d(new Private) | 61 | KGncPriceSourceDlg::KGncPriceSourceDlg(const QString &stockName, const QString& gncSource, QWidget * parent) : | ||
62 | QDialog(parent), | ||||
63 | d_ptr(new KGncPriceSourceDlgPrivate) | ||||
62 | { | 64 | { | ||
63 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Help); | 65 | Q_D(KGncPriceSourceDlg); | ||
64 | QWidget *mainWidget = new QWidget(this); | 66 | d->ui->setupUi(this); | ||
65 | QVBoxLayout *mainLayout = new QVBoxLayout; | | |||
66 | setLayout(mainLayout); | | |||
67 | mainLayout->addWidget(mainWidget); | | |||
68 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | | |||
69 | okButton->setDefault(true); | | |||
70 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | | |||
71 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | | |||
72 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | | |||
73 | d->widget = new KGncPriceSourceDlgDecl(); | | |||
74 | mainLayout->addWidget(d->widget); | | |||
75 | // signals and slots connections | 67 | // signals and slots connections | ||
76 | connect(d->widget->buttonsSource, SIGNAL(buttonClicked(int)), this, SLOT(buttonPressed(int))); | 68 | connect(d->ui->buttonsSource, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &KGncPriceSourceDlg::buttonPressed); | ||
77 | connect(this, SIGNAL(helpClicked()), this, SLOT(slotHelp())); | 69 | connect(d->ui->buttonBox, &QDialogButtonBox::helpRequested, this, &KGncPriceSourceDlg::slotHelp); | ||
78 | // initialize data fields | 70 | // initialize data fields | ||
79 | d->widget->textStockName->setText(i18n("Investment: %1", stockName)); | 71 | d->ui->textStockName->setText(i18n("Investment: %1", stockName)); | ||
80 | d->widget->textGncSource->setText(i18n("Quote source: %1", gncSource)); | 72 | d->ui->textGncSource->setText(i18n("Quote source: %1", gncSource)); | ||
81 | d->widget->listKnownSource->clear(); | 73 | d->ui->listKnownSource->clear(); | ||
82 | d->widget->listKnownSource->insertItems(0, WebPriceQuote::quoteSources()); | 74 | d->ui->listKnownSource->insertItems(0, WebPriceQuote::quoteSources()); | ||
83 | d->widget->lineUserSource->setText(gncSource); | 75 | d->ui->lineUserSource->setText(gncSource); | ||
84 | d->widget->checkAlwaysUse->setChecked(true); | 76 | d->ui->checkAlwaysUse->setChecked(true); | ||
85 | d->widget->buttonsSource->setId(d->widget->buttonNoSource, 0); | 77 | d->ui->buttonsSource->setId(d->ui->buttonNoSource, 0); | ||
86 | d->widget->buttonsSource->setId(d->widget->buttonSelectSource, 1); | 78 | d->ui->buttonsSource->setId(d->ui->buttonSelectSource, 1); | ||
87 | d->widget->buttonsSource->setId(d->widget->buttonUserSource, 2); | 79 | d->ui->buttonsSource->setId(d->ui->buttonUserSource, 2); | ||
88 | d->widget->buttonsSource->button(0)->setChecked(true); | 80 | d->ui->buttonsSource->button(0)->setChecked(true); | ||
89 | mainLayout->addWidget(buttonBox); | | |||
90 | buttonPressed(0); | 81 | buttonPressed(0); | ||
91 | return; | | |||
92 | } | 82 | } | ||
93 | 83 | | |||
94 | KGncPriceSourceDlg::~KGncPriceSourceDlg() | 84 | KGncPriceSourceDlg::~KGncPriceSourceDlg() | ||
95 | { | 85 | { | ||
86 | Q_D(KGncPriceSourceDlg); | ||||
96 | delete d; | 87 | delete d; | ||
97 | } | 88 | } | ||
98 | 89 | | |||
Context not available. | |||||
100 | 91 | | |||
101 | void KGncPriceSourceDlg::buttonPressed(int buttonId) | 92 | void KGncPriceSourceDlg::buttonPressed(int buttonId) | ||
102 | { | 93 | { | ||
94 | Q_D(KGncPriceSourceDlg); | ||||
103 | d->currentButton = buttonId; | 95 | d->currentButton = buttonId; | ||
104 | switch (d->currentButton) { | 96 | switch (d->currentButton) { | ||
105 | case NOSOURCE: | 97 | case NOSOURCE: | ||
106 | d->widget->listKnownSource->clearSelection(); | 98 | d->ui->listKnownSource->clearSelection(); | ||
107 | d->widget->listKnownSource->setEnabled(false); | 99 | d->ui->listKnownSource->setEnabled(false); | ||
108 | d->widget->lineUserSource->deselect(); | 100 | d->ui->lineUserSource->deselect(); | ||
109 | d->widget->lineUserSource->setEnabled(false); | 101 | d->ui->lineUserSource->setEnabled(false); | ||
110 | break; | 102 | break; | ||
111 | case KMMSOURCE: | 103 | case KMMSOURCE: | ||
112 | d->widget->lineUserSource->deselect(); | 104 | d->ui->lineUserSource->deselect(); | ||
113 | d->widget->lineUserSource->setEnabled(false); | 105 | d->ui->lineUserSource->setEnabled(false); | ||
114 | d->widget->listKnownSource->setEnabled(true); | 106 | d->ui->listKnownSource->setEnabled(true); | ||
115 | d->widget->listKnownSource->setFocus(); | 107 | d->ui->listKnownSource->setFocus(); | ||
116 | d->widget->listKnownSource->setCurrentRow(0); | 108 | d->ui->listKnownSource->setCurrentRow(0); | ||
117 | break; | 109 | break; | ||
118 | case USERSOURCE: | 110 | case USERSOURCE: | ||
119 | d->widget->listKnownSource->clearSelection(); | 111 | d->ui->listKnownSource->clearSelection(); | ||
120 | d->widget->listKnownSource->setEnabled(false); | 112 | d->ui->listKnownSource->setEnabled(false); | ||
121 | d->widget->lineUserSource->setEnabled(true); | 113 | d->ui->lineUserSource->setEnabled(true); | ||
122 | d->widget->lineUserSource->selectAll(); | 114 | d->ui->lineUserSource->selectAll(); | ||
123 | d->widget->lineUserSource->setFocus(); | 115 | d->ui->lineUserSource->setFocus(); | ||
124 | break; | 116 | break; | ||
125 | } | 117 | } | ||
126 | } | 118 | } | ||
127 | 119 | | |||
128 | QString KGncPriceSourceDlg::selectedSource() const | 120 | QString KGncPriceSourceDlg::selectedSource() const | ||
129 | { | 121 | { | ||
130 | QString s; | 122 | Q_D(const KGncPriceSourceDlg); | ||
131 | switch (d->currentButton) { | 123 | switch (d->currentButton) { | ||
132 | case NOSOURCE: | | |||
133 | s = ""; | | |||
134 | break; | | |||
135 | case KMMSOURCE: | 124 | case KMMSOURCE: | ||
136 | s = d->widget->listKnownSource->currentItem()->text(); | 125 | return d->ui->listKnownSource->currentItem()->text(); | ||
137 | break; | | |||
138 | case USERSOURCE: | 126 | case USERSOURCE: | ||
139 | s = d->widget->lineUserSource->text(); | 127 | return d->ui->lineUserSource->text(); | ||
140 | break; | 128 | case NOSOURCE: | ||
129 | default: | ||||
130 | return QString(); | ||||
141 | } | 131 | } | ||
142 | return (s); | | |||
143 | } | 132 | } | ||
144 | 133 | | |||
145 | bool KGncPriceSourceDlg::alwaysUse() const | 134 | bool KGncPriceSourceDlg::alwaysUse() const | ||
146 | { | 135 | { | ||
147 | return d->widget->checkAlwaysUse->isChecked(); | 136 | Q_D(const KGncPriceSourceDlg); | ||
137 | return d->ui->checkAlwaysUse->isChecked(); | ||||
148 | } | 138 | } | ||
149 | 139 | | |||
150 | void KGncPriceSourceDlg::slotHelp() | 140 | void KGncPriceSourceDlg::slotHelp() | ||
Context not available. |