Skip to content

Commit

Permalink
Modify connection to refresh ResultsView when a design (name or color)
Browse files Browse the repository at this point in the history
of an item change.
Add all language available in the application setting view
  • Loading branch information
chrono35 committed Oct 18, 2015
1 parent e12efd9 commit 35e11e3
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 15 deletions.
114 changes: 113 additions & 1 deletion src/project/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Project::Project():
mName(tr("Chronomodel Project")),
mProjectFileDir(""),
mProjectFileName(QObject::tr("Untitled"))
//,mModel(0)

{
mState = emptyState();
mLastSavedState = mState;
Expand All @@ -55,6 +55,7 @@ mProjectFileName(QObject::tr("Untitled"))
connect(mAutoSaveTimer, SIGNAL(timeout()), this, SLOT(save()));
mAutoSaveTimer->start(3000);
mModel = new Model();
mRefreshResults =true;
}

Project::~Project()
Expand Down Expand Up @@ -119,13 +120,21 @@ bool Project::pushProjectState(const QJsonObject& state, const QString& reason,
{
if(mState != state || force)
{
if(!mState.isEmpty()) mRefreshResults = checkRefreshResults(state,mState);
else mRefreshResults=true;

SetProjectState* command = new SetProjectState(this, mState, state, reason, notify);
MainWindow::getInstance()->getUndoStack()->push(command);

if(mRefreshResults) {
emit projectDesignChanged(mRefreshResults);
}
return true;
}
return false;
}


void Project::sendUpdateState(const QJsonObject& state, const QString& reason, bool notify)
{
#ifdef DEBUG
Expand All @@ -135,6 +144,109 @@ void Project::sendUpdateState(const QJsonObject& state, const QString& reason, b
QCoreApplication::postEvent(this, event, Qt::NormalEventPriority);
}

bool Project::checkRefreshResults(const QJsonObject& stateNew,const QJsonObject& stateOld)
{
bool refresh=false;

if(stateOld.isEmpty()) {
refresh=true;
return refresh;
}
else {

// Check phase design modification
QJsonArray phaseNew = stateNew[STATE_PHASES].toArray();
QJsonArray phaseOld = stateOld[STATE_PHASES].toArray();
if( phaseNew.size()!=phaseOld.size()) {
refresh=true;
return refresh;
}
else {
for(int i=0; i<phaseNew.size(); ++i){
// Check name of Phases
if(phaseNew[i].toObject()[STATE_NAME] != phaseOld[i].toObject()[STATE_NAME]) {
refresh=true;
return refresh;
}
// Check color of Phases
QColor newPhaseColor=QColor(phaseNew[i].toObject()[STATE_COLOR_RED].toInt(),phaseNew[i].toObject()[STATE_COLOR_GREEN].toInt(),phaseNew[i].toObject()[STATE_COLOR_BLUE ].toInt());
QColor oldPhaseColor=QColor(phaseOld[i].toObject()[STATE_COLOR_RED].toInt(),phaseOld[i].toObject()[STATE_COLOR_GREEN].toInt(),phaseOld[i].toObject()[STATE_COLOR_BLUE ].toInt());
if(newPhaseColor != oldPhaseColor) {
refresh=true;
return refresh;
}
}



}
// Check Event and date design modification
QJsonArray eventNew = stateNew[STATE_EVENTS].toArray();
QJsonArray eventOld = stateOld[STATE_EVENTS].toArray();
if( eventNew.size()!=eventOld.size()) {
refresh=true;
return refresh;
}
else {
for(int i=0; i<eventNew.size(); ++i){
// Check name of Event
if(eventNew[i].toObject()[STATE_NAME] != eventOld[i].toObject()[STATE_NAME]) {
refresh=true;
return refresh;
}
// Check color of Event
QColor newEventColor=QColor(eventNew[i].toObject()[STATE_COLOR_RED].toInt(),eventNew[i].toObject()[STATE_COLOR_GREEN].toInt(),eventNew[i].toObject()[STATE_COLOR_BLUE ].toInt());
QColor oldEventColor=QColor(eventOld[i].toObject()[STATE_COLOR_RED].toInt(),eventOld[i].toObject()[STATE_COLOR_GREEN].toInt(),eventOld[i].toObject()[STATE_COLOR_BLUE ].toInt());
if(newEventColor != oldEventColor) {
refresh=true;
return refresh;
}
// Check date inside Event


QJsonArray datesNew = eventNew[i].toObject()[STATE_EVENT_DATES].toArray();
QJsonArray datesOld = eventOld[i].toObject()[STATE_EVENT_DATES].toArray();
if( datesNew.size()!=datesOld.size()) {
refresh=true;
return refresh;
}

else {
for(int j=0; j<datesNew.size(); ++j){
// Check name of Event
if(datesNew[j].toObject()[STATE_NAME] != datesOld[j].toObject()[STATE_NAME]) {
refresh=true;
return refresh;
}
// No color in date JSON
/*QColor newDateColor=QColor(eventNew[i].toObject()[STATE_COLOR_RED].toInt(),eventNew[i].toObject()[STATE_COLOR_GREEN].toInt(),eventNew[i].toObject()[STATE_COLOR_BLUE ].toInt());
QColor oldDateColor=QColor(eventOld[i].toObject()[STATE_COLOR_RED].toInt(),eventOld[i].toObject()[STATE_COLOR_GREEN].toInt(),eventOld[i].toObject()[STATE_COLOR_BLUE ].toInt());
if(newDateColor != oldDateColor) {
refresh=true;
return refresh;
}
*/
}
}
qDebug()<<"Check date";






}

}
}

return refresh;



}


bool Project::event(QEvent* e)
{
if(e->type() == QEvent::User)
Expand Down
5 changes: 4 additions & 1 deletion src/project/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Project: public QObject
// An undo command is created and a StateEvent is fired asynchronously.
// The project state will be modified and the view notified (if required)
bool pushProjectState(const QJsonObject& state, const QString& reason, bool notify, bool force = false);

bool checkRefreshResults(const QJsonObject& stateNew,const QJsonObject& stateOld);
// Sends a StateEvent asynchronously.
// Called by "SetProjectState" undo/redo commands.
void sendUpdateState(const QJsonObject& state, const QString& reason, bool notify);
Expand Down Expand Up @@ -73,6 +73,7 @@ class Project: public QObject
void showStudyPeriodWarning();

bool isValid();
bool mRefreshResults;

// ---------------------------

Expand Down Expand Up @@ -150,6 +151,8 @@ public slots:

void mcmcStarted();
void mcmcFinished(Model* model);

void projectDesignChanged(bool designChanged);

public:
QJsonObject mState;
Expand Down
17 changes: 12 additions & 5 deletions src/ui/dialogs/AppSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ QDialog(parent, flags)

mLanguageLab = new QLabel(tr("Language") + " : ", this);
mLanguageCombo = new QComboBox(this);
mLanguageCombo->addItem(QLocale::languageToString(QLocale::French), QVariant(QLocale::French));
mLanguageCombo->addItem(QLocale::languageToString(QLocale::English), QVariant(QLocale::English));
//mLanguageCombo->addItem(QLocale::languageToString(QLocale::French), QVariant(QLocale::French));
//mLanguageCombo->addItem(QLocale::languageToString(QLocale::English), QVariant(QLocale::English));
//mLanguageCombo->addItem(QLocale::languageToString(QLocale::German), QVariant(QLocale::German));
//mLanguageCombo->addItem(QLocale::languageToString(QLocale::Spanish), QVariant(QLocale::Spanish));
QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);


/*for(int i=0; i<allLocales.size(); i++) {
mLanguageCombo->addItem(QLocale::languageToString(allLocales[i].language()),QVariant(allLocales[i].language()));
}*/
for(int i=0; i<339; i++) {
mLanguageCombo->addItem(QLocale::languageToString((QLocale::Language)i),QVariant((QLocale::Language)i));
}

mCountryLab = new QLabel(tr("Country") + " : ", this);
mCountryCombo = new QComboBox(this);
Expand Down Expand Up @@ -306,9 +312,10 @@ void AppSettingsDialog::buttonClicked(QAbstractButton* button)
mAutoSaveDelayEdit->setText(locale().toString(APP_SETTINGS_DEFAULT_AUTO_SAVE_DELAY_SEC / 60));
mAutoSaveDelayEdit->setEnabled(true);

if(QLocale::system().language()==QLocale::French) {
//if(QLocale::system().language()==QLocale::French) {
if(QLocale::system().decimalPoint()==',') {
mCSVCellSepEdit->setText(";");
mCSVDecSepCombo->setCurrentIndex(0);
mCSVDecSepCombo->setCurrentIndex(0);
}
else {
mCSVCellSepEdit->setText(",");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/panel_results/ResultsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void ResultsView::clearResults()
void ResultsView::updateResults(Model* model)
{
clearResults();

qDebug() << "ResultsView::updateResults";

if(!mModel && !model)
Expand Down
5 changes: 2 additions & 3 deletions src/ui/window/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ MainWindow::MainWindow(QWidget* aParent):QMainWindow(aParent)
connect(mProject, SIGNAL(mcmcFinished(Model*)), this, SLOT(mcmcFinished(Model*)));

connect(mViewResultsAction, SIGNAL(triggered()), mProjectView, SLOT(showResults()));


connect(mProject, &Project::projectDesignChanged, mProjectView, &ProjectView::changeDesign);


mProjectView->doProjectConnections(mProject);
Expand All @@ -78,10 +79,8 @@ MainWindow::MainWindow(QWidget* aParent):QMainWindow(aParent)
QLocale newLoc(QLocale::system());
mAppSettings.mLanguage = newLoc.language();
mAppSettings.mCountry = newLoc.country();
//QLocale newLoc = QLocale(mLanguage,mCountry);
newLoc.setNumberOptions(QLocale::OmitGroupSeparator);
QLocale::setDefault(newLoc);
//if(mLanguage==QLocale::French) {
if(newLoc.decimalPoint()==',') {
mAppSettings.mCSVCellSeparator=";";
mAppSettings.mCSVDecSeparator=",";
Expand Down
21 changes: 18 additions & 3 deletions src/ui/window/ProjectView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void ProjectView::doProjectConnections(Project* project)
{
mModelView -> doProjectConnections(project);
mResultsView -> doProjectConnections(project);
//connect(*project, SIGNAL(designChanged(bool)), this, SLOT(changeDesign(bool)));
}

#pragma mark Interface
Expand All @@ -94,8 +95,22 @@ void ProjectView::showModel()

mStack->setCurrentIndex(0);
}
void ProjectView::showResults(bool updateModel)

/**
* @brief ProjectView::changeDesign solt connected to Project::projectDesignChange() in MainWindows
* @param refresh
*/
void ProjectView::changeDesign(bool refresh)
{
mRefreshResults = refresh;
}

void ProjectView::showResults()
{
if(mRefreshResults) {
mResultsView->updateResults();
mRefreshResults=false;
}
mStack->setCurrentIndex(1);
// come from mViewResultsAction and updateResults send repaint on mStack
}
Expand All @@ -107,7 +122,7 @@ void ProjectView::showLog()

#pragma mark Update Model
/**
* @brief : Update All model views (Scenes, ...) after pushing state
* @brief Update All model views (Scenes, ...) after pushing state
*/
void ProjectView::updateProject()
{
Expand Down Expand Up @@ -136,7 +151,7 @@ void ProjectView::updateResults(Model* model)
{
if(model)
{
showResults(false);
showResults();//false);

mResultsView->updateResults(model);

Expand Down
6 changes: 5 additions & 1 deletion src/ui/window/ProjectView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ProjectView: public QWidget
ProjectView(QWidget* parent = 0, Qt::WindowFlags flags = 0);
~ProjectView();

bool mRefreshResults;

void doProjectConnections(Project* project);
void resetInterface();

Expand All @@ -30,7 +32,9 @@ class ProjectView: public QWidget
public slots:
void updateProject();
void showModel();
void showResults(bool updateModel = true);
void showResults();

void changeDesign(bool refresh);
void showLog();
void showHelp(bool show);

Expand Down

0 comments on commit 35e11e3

Please sign in to comment.