Commit ad3960de authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Initialize value in header. Minor optimzation

parent c81231b6
......@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Name: BitButton
// Desc: constructor
//------------------------------------------------------------------------------
BitButton::BitButton(QWidget *parent) : QAbstractButton(parent), on_(false) , over_(false) {
BitButton::BitButton(QWidget *parent) : QAbstractButton(parent) {
// too many bits for tab focus
setFocusPolicy(Qt::ClickFocus);
......
......@@ -29,7 +29,7 @@ class BitButton : public QAbstractButton {
public:
explicit BitButton(QWidget *parent = nullptr);
bool isOn() const;
Q_REQUIRED_RESULT bool isOn() const;
void setOn(bool value);
protected:
......@@ -38,8 +38,8 @@ protected:
private:
void enterEvent(QEvent * event) override;
void leaveEvent(QEvent * event) override;
bool on_;
bool over_;
bool on_ = false;
bool over_ = false;
};
#endif
......@@ -67,11 +67,7 @@ const int maxprecision = 1000;
//------------------------------------------------------------------------------
KCalculator::KCalculator(QWidget *parent) :
KXmlGuiWindow(parent),
shift_mode_(false),
hyp_mode_(false),
memory_num_(0.0),
constants_menu_(nullptr),
constants_(nullptr),
core() {
// central widget to contain all the elements
......@@ -611,7 +607,7 @@ void KCalculator::setupMiscKeys() {
pbPower->setShortcut(QKeySequence(Qt::Key_AsciiCircum));
connect(pbPower, &KCalcButton::clicked, this, &KCalculator::slotPowerclicked);
pbEE->addMode(ModeNormal, QLatin1String("x<small>" "\xb7" "10</small><sup>y</sup>"), i18n("Exponent"));
pbEE->addMode(ModeNormal, QStringLiteral("x<small>" "\xb7" "10</small><sup>y</sup>"), i18n("Exponent"));
connect(this, &KCalculator::switchShowAccels, pbEE, &KCalcButton::slotSetAccelDisplayMode);
connect(pbEE, &KCalcButton::clicked, this, &KCalculator::slotEEclicked);
}
......
......@@ -250,20 +250,20 @@ private:
};
private:
bool shift_mode_;
bool hyp_mode_;
bool shift_mode_ = false;
bool hyp_mode_ = false;
KNumber memory_num_;
int angle_mode_; // angle modes for trigonometric values
KCalcConstMenu* constants_menu_;
KCalcConstMenu* constants_menu_ = nullptr;
Constants* constants_; // this is the dialog for configuring const buttons
Constants* constants_ = nullptr; // this is the dialog for configuring const buttons
QButtonGroup* angle_choose_group_;
QButtonGroup* base_choose_group_;
QButtonGroup* angle_choose_group_ = nullptr;
QButtonGroup* base_choose_group_ = nullptr;
// num_button_group_: 0-9 = digits, 0xA-0xF = hex-keys
QButtonGroup* num_button_group_;
QButtonGroup* num_button_group_ = nullptr;
QList<QAbstractButton*> logic_buttons_;
QList<QAbstractButton*> scientific_buttons_;
......@@ -272,13 +272,13 @@ private:
std::array<QLabel*, 4> base_conversion_labels_;
KToggleAction *action_bitset_show_;
KToggleAction *action_constants_show_;
KToggleAction *action_bitset_show_ = nullptr;
KToggleAction *action_constants_show_ = nullptr;
KToggleAction *action_mode_simple_;
KToggleAction *action_mode_science_;
KToggleAction *action_mode_statistic_;
KToggleAction *action_mode_numeral_;
KToggleAction *action_mode_simple_ = nullptr;
KToggleAction *action_mode_science_ = nullptr;
KToggleAction *action_mode_statistic_ = nullptr;
KToggleAction *action_mode_numeral_ = nullptr;
QList<QAbstractButton*> function_button_list_;
QList<QAbstractButton*> stat_button_list_;
......
......@@ -31,7 +31,7 @@ class KCalcBitset : public QFrame {
public:
explicit KCalcBitset(QWidget *parent = nullptr);
quint64 getValue() const;
Q_REQUIRED_RESULT quint64 getValue() const;
public Q_SLOTS:
void setValue(quint64 value);
......
......@@ -32,7 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Name: KCalcButton
// Desc: constructor
//------------------------------------------------------------------------------
KCalcButton::KCalcButton(QWidget *parent) : QPushButton(parent), show_shortcut_mode_(false), mode_flags_(ModeNormal), size_() {
KCalcButton::KCalcButton(QWidget *parent) : QPushButton(parent), mode_flags_(ModeNormal), size_() {
setAcceptDrops(true); // allow color drops
setFocusPolicy(Qt::TabFocus);
......@@ -47,7 +47,7 @@ KCalcButton::KCalcButton(QWidget *parent) : QPushButton(parent), show_shortcut_m
// Name: KCalcButton
// Desc: constructor
//------------------------------------------------------------------------------
KCalcButton::KCalcButton(const QString &label, QWidget *parent, const QString &tooltip) : QPushButton(label, parent), show_shortcut_mode_(false), mode_flags_(ModeNormal), size_() {
KCalcButton::KCalcButton(const QString &label, QWidget *parent, const QString &tooltip) : QPushButton(label, parent), mode_flags_(ModeNormal), size_() {
setAutoDefault(false);
addMode(ModeNormal, label, tooltip);
......
......@@ -84,7 +84,7 @@ private:
void calcSizeHint();
private:
bool show_shortcut_mode_;
bool show_shortcut_mode_ = false;
ButtonModeFlags mode_flags_;
QMap<ButtonModeFlags, ButtonMode> mode_;
QSize size_;
......
......@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Name: KCalcConstButton
// Desc: constructor
//------------------------------------------------------------------------------
KCalcConstButton::KCalcConstButton(QWidget *parent) : KCalcButton(parent), button_num_(-1) {
KCalcConstButton::KCalcConstButton(QWidget *parent) : KCalcButton(parent) {
setTextColor(KCalcSettings::constantsFontsColor());
addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
......@@ -45,7 +45,7 @@ KCalcConstButton::KCalcConstButton(QWidget *parent) : KCalcButton(parent), butto
// Name: KCalcConstButton
// Desc: constructor
//------------------------------------------------------------------------------
KCalcConstButton::KCalcConstButton(const QString &label, QWidget *parent, const QString &tooltip) : KCalcButton(label, parent, tooltip), button_num_(-1) {
KCalcConstButton::KCalcConstButton(const QString &label, QWidget *parent, const QString &tooltip) : KCalcButton(label, parent, tooltip) {
setTextColor(KCalcSettings::constantsFontsColor());
addMode(ModeShift, i18nc("Write display data into memory", "Store"), i18n("Write display data into memory"));
......
......@@ -55,7 +55,7 @@ private:
void initPopupMenu();
private:
int button_num_;
int button_num_ = -1;
};
......
......@@ -112,18 +112,19 @@ void KCalcConstMenu::init_all()
connect(this, &KCalcConstMenu::triggered, this, &KCalcConstMenu::slotPassSignalThrough);
for (int i = 0; i < scienceConstantList.size(); i++) {
auto tmp_action = new QAction(i18n(scienceConstantList.at(i).name.toLatin1().data()), this);
for (int i = 0, total = scienceConstantList.size(); i < total; ++i) {
const auto scienceConstantListItem = scienceConstantList.at(i);
auto tmp_action = new QAction(i18n(scienceConstantListItem.name.toLatin1().data()), this);
tmp_action->setData(QVariant(i));
if (scienceConstantList.at(i).category & Mathematics)
if (scienceConstantListItem.category & Mathematics)
math_menu->addAction(tmp_action);
if (scienceConstantList.at(i).category & Electromagnetic)
if (scienceConstantListItem.category & Electromagnetic)
em_menu->addAction(tmp_action);
if (scienceConstantList.at(i).category & Nuclear)
if (scienceConstantListItem.category & Nuclear)
nuclear_menu->addAction(tmp_action);
if (scienceConstantList.at(i).category & Thermodynamics)
if (scienceConstantListItem.category & Thermodynamics)
thermo_menu->addAction(tmp_action);
if (scienceConstantList.at(i).category & Gravitation)
if (scienceConstantListItem.category & Gravitation)
gravitation_menu->addAction(tmp_action);
}
}
......
......@@ -150,7 +150,7 @@ private:
QString str_int_exp_;
QString str_status_[NUM_STATUS_TEXT];
QTimer* selection_timer_;
QTimer *const selection_timer_;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment