Skip to content
Snippets Groups Projects
Commit 19994b2d authored by SeeLook's avatar SeeLook :musical_note:
Browse files

Disable sorting by key for single key exams, fixed crash when settings tool button was clicked

parent e4cd5a3a
No related branches found
No related tags found
No related merge requests found
/*************************************************************************** /***************************************************************************
* Copyright (C) 2012-2015 by Tomasz Bojczuk * * Copyright (C) 2012-2016 by Tomasz Bojczuk *
* tomaszbojczuk@gmail.com * * tomaszbojczuk@gmail.com *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
...@@ -43,9 +43,9 @@ ...@@ -43,9 +43,9 @@
TanalysDialog::TanalysDialog(Texam* exam, QWidget* parent) : TanalysDialog::TanalysDialog(Texam* exam, QWidget* parent) :
QDialog(parent), QDialog(parent),
m_chart(0),
m_exam(0), m_exam(0),
m_level(new Tlevel()), m_level(new Tlevel()),
m_chart(0),
m_wasExamCreated(false), m_wasExamCreated(false),
m_isMaximized(false) m_isMaximized(false)
{ {
...@@ -221,7 +221,7 @@ void TanalysDialog::setExam(Texam* exam) { ...@@ -221,7 +221,7 @@ void TanalysDialog::setExam(Texam* exam) {
else else
enableComboItem(m_XorderCombo, 2, false); enableComboItem(m_XorderCombo, 2, false);
// sort by key signature // sort by key signature
if (m_exam->level()->canBeScore() && m_exam->level()->useKeySign) if (m_exam->level()->canBeScore() && m_exam->level()->useKeySign && !m_exam->level()->isSingleKey)
enableComboItem(m_XorderCombo, 3, true); enableComboItem(m_XorderCombo, 3, true);
else else
enableComboItem(m_XorderCombo, 3, false); enableComboItem(m_XorderCombo, 3, false);
...@@ -299,7 +299,7 @@ void TanalysDialog::createActions() { ...@@ -299,7 +299,7 @@ void TanalysDialog::createActions() {
QString exerciseFile = QDir::toNativeSeparators(QFileInfo(Tcore::gl()->config->fileName()).absolutePath() + "/exercise.noo"); QString exerciseFile = QDir::toNativeSeparators(QFileInfo(Tcore::gl()->config->fileName()).absolutePath() + "/exercise.noo");
if (QFileInfo(exerciseFile).exists()) { if (QFileInfo(exerciseFile).exists()) {
Tlevel lev; Tlevel lev;
Texam ex(&lev, ""); Texam ex(&lev, QString());
ex.loadFromFile(exerciseFile); ex.loadFromFile(exerciseFile);
QAction *exerciseAct = new QAction(tr("Recent exercise on level") + ": " + lev.name, this); QAction *exerciseAct = new QAction(tr("Recent exercise on level") + ": " + lev.name, this);
exerciseAct->setIcon(QIcon(Tcore::gl()->path + "picts/practice.png")); exerciseAct->setIcon(QIcon(Tcore::gl()->path + "picts/practice.png"));
...@@ -339,21 +339,22 @@ void TanalysDialog::createActions() { ...@@ -339,21 +339,22 @@ void TanalysDialog::createActions() {
m_inclWrongAct->setCheckable(true); m_inclWrongAct->setCheckable(true);
m_wrongSeparateAct = new QAction(tr("show wrong answers separately"), this); m_wrongSeparateAct = new QAction(tr("show wrong answers separately"), this);
m_wrongSeparateAct->setCheckable(true); m_wrongSeparateAct->setCheckable(true);
m_wrongSeparateAct->setChecked(m_chartSetts.separateWrong);
m_inclWrongAct->setChecked(m_chartSetts.inclWrongAnsw);
m_wrongSeparateAct->setDisabled(true); // that options makes no sense for default chart
m_inclWrongAct->setDisabled(true);
QMenu *menu = new QMenu("chart menu", this); QMenu *menu = new QMenu("chart menu", this);
menu->addAction(m_wrongSeparateAct); menu->addAction(m_wrongSeparateAct);
menu->addAction(m_inclWrongAct); menu->addAction(m_inclWrongAct);
connect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot())); connect(m_wrongSeparateAct, SIGNAL(triggered()), this, SLOT(wrongSeparateSlot()), Qt::UniqueConnection);
connect(m_inclWrongAct, SIGNAL(changed()), this, SLOT(includeWrongSlot())); connect(m_inclWrongAct, SIGNAL(triggered()), this, SLOT(includeWrongSlot()), Qt::UniqueConnection);
m_wrongSeparateAct->setChecked(m_chartSetts.separateWrong);
m_inclWrongAct->setChecked(m_chartSetts.inclWrongAnsw);
m_settButt = new QToolButton(this); m_settButt = new QToolButton(this);
m_settButt->setIcon(QIcon(Tcore::gl()->path + "picts/exam-settings.png")); m_settButt->setIcon(QIcon(Tcore::gl()->path + "picts/exam-settings.png"));
m_settButt->setToolTip(tr("Settings of a chart")); m_settButt->setToolTip(tr("Settings of a chart"));
m_settButt->setMenu(menu); m_settButt->setMenu(menu);
m_settButt->setPopupMode(QToolButton::InstantPopup); m_settButt->setPopupMode(QToolButton::InstantPopup);
m_settButt->setDisabled(true); // that options have no sense for default chart
QWidgetAction* toolButtonAction = new QWidgetAction(this); QWidgetAction* toolButtonAction = new QWidgetAction(this);
toolButtonAction->setDefaultWidget(m_settButt); toolButtonAction->setDefaultWidget(m_settButt);
...@@ -466,10 +467,10 @@ void TanalysDialog::openRecentExam() { ...@@ -466,10 +467,10 @@ void TanalysDialog::openRecentExam() {
void TanalysDialog::xOrderChanged(int index) { void TanalysDialog::xOrderChanged(int index) {
if (!m_exam) if (!m_exam)
return; return;
if (index)
m_settButt->setDisabled(false); m_wrongSeparateAct->setDisabled(index == 0);
else m_inclWrongAct->setDisabled(index == 0);
m_settButt->setDisabled(true);
switch (index) { switch (index) {
case 0: case 0:
m_chartSetts.order = Tchart::e_byNumber; m_chartSetts.order = Tchart::e_byNumber;
...@@ -494,15 +495,15 @@ void TanalysDialog::xOrderChanged(int index) { ...@@ -494,15 +495,15 @@ void TanalysDialog::xOrderChanged(int index) {
break; break;
} }
if (m_chartSetts.order == Tchart::e_byQuestAndAnsw || m_chartSetts.order == Tchart::e_byMistake) { if (m_chartSetts.order == Tchart::e_byQuestAndAnsw || m_chartSetts.order == Tchart::e_byMistake) {
disconnect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot())); disconnect(m_wrongSeparateAct, SIGNAL(triggered()), this, SLOT(wrongSeparateSlot()));
m_wrongSeparateAct->setChecked(false); // this sorting types require it!! m_wrongSeparateAct->setChecked(false); // this sorting types require it!!
m_wrongSeparateAct->setDisabled(true); m_wrongSeparateAct->setDisabled(true);
m_chartSetts.separateWrong = false; m_chartSetts.separateWrong = false;
m_inclWrongAct->setDisabled(false); m_inclWrongAct->setDisabled(false);
} else { } else {
m_wrongSeparateAct->setDisabled(false); m_wrongSeparateAct->setDisabled(false);
connect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot())); connect(m_wrongSeparateAct, SIGNAL(triggered()), this, SLOT(wrongSeparateSlot()), Qt::UniqueConnection);
} }
createChart(m_chartSetts); createChart(m_chartSetts);
} }
...@@ -510,10 +511,10 @@ void TanalysDialog::xOrderChanged(int index) { ...@@ -510,10 +511,10 @@ void TanalysDialog::xOrderChanged(int index) {
void TanalysDialog::yValueChanged(int index) { void TanalysDialog::yValueChanged(int index) {
if (!m_exam) if (!m_exam)
return; return;
if (index)
m_settButt->setDisabled(false); m_wrongSeparateAct->setDisabled(index == 0);
else m_inclWrongAct->setDisabled(index == 0);
m_settButt->setDisabled(true);
switch (index) { switch (index) {
case 0: case 0:
m_chartSetts.yValue = TmainLine::e_questionTime; m_chartSetts.yValue = TmainLine::e_questionTime;
...@@ -557,15 +558,15 @@ void TanalysDialog::maximizeWindow() { ...@@ -557,15 +558,15 @@ void TanalysDialog::maximizeWindow() {
void TanalysDialog::wrongSeparateSlot() { void TanalysDialog::wrongSeparateSlot() {
m_chartSetts.separateWrong = m_wrongSeparateAct->isChecked(); m_chartSetts.separateWrong = m_wrongSeparateAct->isChecked();
if (m_wrongSeparateAct->isChecked()) { if (m_wrongSeparateAct->isChecked()) {
disconnect(m_inclWrongAct, SIGNAL(changed()), this, SLOT(includeWrongSlot())); disconnect(m_inclWrongAct, SIGNAL(triggered()), this, SLOT(includeWrongSlot()));
m_inclWrongAct->setDisabled(true); // wrong separeted - it has no sense - lock it! m_inclWrongAct->setDisabled(true); // wrong separeted - it has no sense - lock it!
m_chartSetts.inclWrongAnsw = false; // and reset m_chartSetts.inclWrongAnsw = false; // and reset
m_inclWrongAct->setChecked(false); m_inclWrongAct->setChecked(false);
} }
else { else {
disconnect(m_inclWrongAct, SIGNAL(changed()), this, SLOT(includeWrongSlot())); disconnect(m_inclWrongAct, SIGNAL(triggered()), this, SLOT(includeWrongSlot()));
m_inclWrongAct->setDisabled(false); // unlock m_inclWrongAct->setDisabled(false); // unlock
connect(m_inclWrongAct, SIGNAL(changed()), this, SLOT(includeWrongSlot())); connect(m_inclWrongAct, SIGNAL(triggered()), this, SLOT(includeWrongSlot()), Qt::UniqueConnection);
} }
createChart(m_chartSetts); createChart(m_chartSetts);
} }
...@@ -604,11 +605,12 @@ void TanalysDialog::chartTypeChanged() { ...@@ -604,11 +605,12 @@ void TanalysDialog::chartTypeChanged() {
m_wrongSeparateAct->setDisabled(false); m_wrongSeparateAct->setDisabled(false);
connect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot())); connect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot()));
createChart(m_chartSetts); createChart(m_chartSetts);
} }
} else { // bar chart } else { // bar chart
if (m_chartSetts.type != Tchart::e_bar) { if (m_chartSetts.type != Tchart::e_bar) {
m_chartSetts.type = Tchart::e_bar; m_chartSetts.type = Tchart::e_bar;
m_settButt->setDisabled(false); // unlock settings m_wrongSeparateAct->setDisabled(false); // unlock settings
m_inclWrongAct->setDisabled(false);
disconnect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot())); disconnect(m_wrongSeparateAct, SIGNAL(changed()), this, SLOT(wrongSeparateSlot()));
m_wrongSeparateAct->setDisabled(true); m_wrongSeparateAct->setDisabled(true);
m_wrongSeparateAct->setChecked(false); m_wrongSeparateAct->setChecked(false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment