File: dialog_favourite.cpp

package info (click to toggle)
evolvotron 0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,420 kB
  • ctags: 1,367
  • sloc: cpp: 10,462; python: 162; sh: 147; makefile: 9
file content (139 lines) | stat: -rw-r--r-- 4,604 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**************************************************************************/
/*  Copyright 2012 Tim Day                                                */
/*                                                                        */
/*  This file is part of Evolvotron                                       */
/*                                                                        */
/*  Evolvotron is free software: you can redistribute it and/or modify    */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation, either version 3 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/*  Evolvotron is distributed in the hope that it will be useful,         */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
/*  GNU General Public License for more details.                          */
/*                                                                        */
/*  You should have received a copy of the GNU General Public License     */
/*  along with Evolvotron.  If not, see <http://www.gnu.org/licenses/>.   */
/**************************************************************************/

/*! \file
  \brief Implementation of class DialogFavourite.
*/

#include "libevolvotron_precompiled.h"

#include "dialog_favourite.h"

#include "function_registry.h"
#include "evolvotron_main.h"

DialogFavourite::DialogFavourite(EvolvotronMain* parent)
  :QDialog(parent)
  ,_parent(parent)
  ,_favourite_function_unwrapped(false)
{
  setWindowTitle("Favourite");
  setSizeGripEnabled(true);

  setLayout(new QVBoxLayout);
  
  QGroupBox*const group0=new QGroupBox("Function");
  group0->setLayout(new QVBoxLayout);
  layout()->addWidget(group0);

  group0->layout()->addWidget(new QLabel("Root node for new image functions:"));
  _favourite=new QComboBox;
  group0->layout()->addWidget(_favourite);
  _favourite_fn_to_index[""]=_favourite->count();
  _index_to_favourite_fn[_favourite->count()]="";
  _favourite->addItem("- No preference -");

  for (FunctionRegistry::Registrations::const_iterator it=_parent->mutation_parameters().function_registry().registrations().begin();
       it!=_parent->mutation_parameters().function_registry().registrations().end();
       it++
       )
    {
      const FunctionRegistration& fn=
#if BOOST_VERSION >= 103400
      *(it->second);
#else
      *it;
#endif
      _favourite_fn_to_index[fn.name()]=_favourite->count();
      _index_to_favourite_fn[_favourite->count()]=fn.name();
      _favourite->addItem(fn.name().c_str());
    }

  QGroupBox*const group1=new QGroupBox("Wrapping");
  group1->setLayout(new QVBoxLayout);
  layout()->addWidget(group1);
  
  _unwrapped=new QCheckBox("Disable additional space/colour transforms");
  group1->layout()->addWidget(_unwrapped);

  //! \todo: Add OK & reset/restart versions ?
  QPushButton*const ok=new QPushButton("OK");
  layout()->addWidget(ok);
  ok->setDefault(true);

  update_gui_from_state();

  connect(_favourite,SIGNAL(activated(int)),this,SLOT(changed_favourite(int)));
  
  connect(_unwrapped,SIGNAL(toggled(bool)),this,SLOT(changed_unwrapped(bool)));

  connect(ok,SIGNAL(clicked()),this,SLOT(hide()));
}

DialogFavourite::~DialogFavourite()
{}

void DialogFavourite::changed_favourite(int i)
{
  const std::map<unsigned int,std::string>::const_iterator it=_index_to_favourite_fn.find(i);
  if (it!=_index_to_favourite_fn.end())
    {
      _favourite_function=(*it).second;
    }

  update_gui_from_state();
}

void DialogFavourite::changed_unwrapped(bool b)
{
  _favourite_function_unwrapped=b;

  update_gui_from_state();
}

void DialogFavourite::update_gui_from_state()
{
  const std::map<std::string,unsigned int>::const_iterator it=_favourite_fn_to_index.find(_favourite_function);
  if (it!=_favourite_fn_to_index.end())
    _favourite->setCurrentIndex((*it).second);
  else
    _favourite->setCurrentIndex(0);

  _unwrapped->setChecked(_favourite_function_unwrapped);

  _unwrapped->setEnabled(!_favourite_function.empty());
}

bool DialogFavourite::favourite_function(const std::string& f)
{
  if (_parent->mutation_parameters().function_registry().lookup(f))
    {
      _favourite_function=f;
      update_gui_from_state();
      return true;
    }
  else
    return false;
}

void DialogFavourite::favourite_function_unwrapped(bool v)
{
  _favourite_function_unwrapped=v;
  update_gui_from_state();
}