diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Preferences.cc | 32 | ||||
-rw-r--r-- | src/Preferences.h | 10 | ||||
-rw-r--r-- | src/feature.cc | 46 | ||||
-rw-r--r-- | src/feature.h | 60 | ||||
-rw-r--r-- | src/openscad.cc | 7 |
5 files changed, 58 insertions, 97 deletions
diff --git a/src/Preferences.cc b/src/Preferences.cc index 9eef43a..591ccf6 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -33,9 +33,9 @@ #include <QStatusBar> #include "PolySetCache.h" #include "AutoUpdater.h" +#include "feature.h" #ifdef ENABLE_CGAL #include "CGALCache.h" -#include "feature.h" #endif Preferences *Preferences::instance = NULL; @@ -204,7 +204,7 @@ void Preferences::featuresCheckBoxToggled(bool state) Feature *feature = v.value<Feature *>(); feature->enable(state); QSettings settings; - settings.setValue(feature->get_name().c_str(), state); + settings.setValue(QString("feature/%1").arg(QString::fromStdString(feature->get_name())), state); } /** @@ -220,37 +220,29 @@ Preferences::setupFeaturesPage() { int row = 0; for (Feature::iterator it = Feature::begin();it != Feature::end();it++) { - Feature * feature = (*it); - // setup default with the current value coming from commandline - this->defaultmap[feature->get_name().c_str()] = false; + Feature *feature = *it; + QString featurekey = QString("feature/%1").arg(QString::fromStdString(feature->get_name())); + this->defaultmap[featurekey] = false; + // spacer item between the features, just for some optical separation gridLayoutExperimentalFeatures->addItem(new QSpacerItem(1, 8, QSizePolicy::Expanding, QSizePolicy::Fixed), row, 1, 1, 1, Qt::AlignCenter); row++; - std::string text(feature->get_name()); - QCheckBox *cb = new QCheckBox(text.c_str(), pageFeatures); + QCheckBox *cb = new QCheckBox(QString::fromStdString(feature->get_name()), pageFeatures); QFont bold_font(cb->font()); bold_font.setBold(true); cb->setFont(bold_font); - if (feature->is_enabled()) { - // if enabled from command line, that has priority - cb->setChecked(true); - cb->setEnabled(false); - std::string text_cl = text + " (enabled on commandline)"; - cb->setText(text_cl.c_str()); - } else { - // synchronize Qt settings with the feature settings - bool value = getValue(feature->get_name().c_str()).toBool(); - feature->enable(value); - cb->setChecked(value); - } + // synchronize Qt settings with the feature settings + bool value = getValue(featurekey).toBool(); + feature->enable(value); + cb->setChecked(value); cb->setProperty(featurePropertyName, QVariant::fromValue<Feature *>(feature)); connect(cb, SIGNAL(toggled(bool)), this, SLOT(featuresCheckBoxToggled(bool))); gridLayoutExperimentalFeatures->addWidget(cb, row, 0, 1, 2, Qt::AlignLeading); row++; - QLabel *l = new QLabel(feature->get_description().c_str(), pageFeatures); + QLabel *l = new QLabel(QString::fromStdString(feature->get_description()), pageFeatures); l->setTextFormat(Qt::RichText); gridLayoutExperimentalFeatures->addWidget(l, row, 1, 1, 1, Qt::AlignLeading); row++; diff --git a/src/Preferences.h b/src/Preferences.h index 6310622..ef8835a 100644 --- a/src/Preferences.h +++ b/src/Preferences.h @@ -21,7 +21,7 @@ public: public slots: void actionTriggered(class QAction *); - void featuresCheckBoxToggled(bool); + void featuresCheckBoxToggled(bool); void on_colorSchemeChooser_itemSelectionChanged(); void on_fontChooser_activated(const QString &); void on_fontSize_editTextChanged(const QString &); @@ -45,15 +45,15 @@ private: void keyPressEvent(QKeyEvent *e); void updateGUI(); void removeDefaultSettings(); - void setupFeaturesPage(); - void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget); + void setupFeaturesPage(); + void addPrefPage(QActionGroup *group, QAction *action, QWidget *widget); QSettings::SettingsMap defaultmap; QHash<QString, std::map<RenderSettings::RenderColor, Color4f> > colorschemes; - QHash<const QAction *, QWidget *> prefPages; + QHash<const QAction *, QWidget *> prefPages; static Preferences *instance; - static const char *featurePropertyName; + static const char *featurePropertyName; }; #endif diff --git a/src/feature.cc b/src/feature.cc index 7f36547..80d7887 100644 --- a/src/feature.cc +++ b/src/feature.cc @@ -18,11 +18,12 @@ Feature::list_t Feature::feature_list; * argument to enable the option and for saving the option value in GUI * context. */ -const Feature Feature::ExperimentalConcatFunction("experimental/concat-function", "Enable the <code>concat()</code> function."); +const Feature Feature::ExperimentalConcatFunction("concat", "Enable the <code>concat()</code> function."); -Feature::Feature(const std::string name, const std::string description) : enabled_cmdline(false), enabled_options(false), name(name), description(description) +Feature::Feature(const std::string &name, const std::string &description) + : enabled(false), name(name), description(description) { - feature_map[name] = this; + feature_map[name] = this; feature_list.push_back(this); } @@ -30,57 +31,36 @@ Feature::~Feature() { } -const std::string& Feature::get_name() const +const std::string &Feature::get_name() const { - return name; + return name; } -const std::string& Feature::get_description() const +const std::string &Feature::get_description() const { - return description; + return description; } -void Feature::set_enable_cmdline() -{ - enabled_cmdline = true; -} - -void Feature::set_enable_options(bool status) -{ - enabled_options = status; -} - bool Feature::is_enabled() const { - if (enabled_cmdline) { - return true; - } - return enabled_options; + return enabled; } void Feature::enable(bool status) { - set_enable_options(status); + enabled = status; } -void Feature::enable_feature(std::string feature_name) +void Feature::enable_feature(const std::string &feature_name, bool status) { map_t::iterator it = feature_map.find(feature_name); if (it != feature_map.end()) { - (*it).second->set_enable_cmdline(); + it->second->enable(status); } else { PRINTB("WARNING: Ignoring request to enable unknown feature '%s'.", feature_name); } } -void Feature::enable_feature(std::string feature_name, bool status) -{ - map_t::iterator it = feature_map.find(feature_name); - if (it != feature_map.end()) { - (*it).second->set_enable_options(status); - } -} - Feature::iterator Feature::begin() { return feature_list.begin(); @@ -94,6 +74,6 @@ Feature::iterator Feature::end() void Feature::dump_features() { for (map_t::iterator it = feature_map.begin(); it != feature_map.end(); it++) { - std::cout << "Feature('" << (*it).first << "') = " << ((*it).second->is_enabled() ? "enabled" : "disabled") << std::endl; + std::cout << "Feature('" << it->first << "') = " << (it->second->is_enabled() ? "enabled" : "disabled") << std::endl; } } diff --git a/src/feature.h b/src/feature.h index 77e283c..20b4f16 100644 --- a/src/feature.h +++ b/src/feature.h @@ -7,50 +7,38 @@ #include <map> #include <vector> -class Feature { +class Feature +{ public: - typedef std::vector<Feature *> list_t; - typedef list_t::iterator iterator; + typedef std::vector<Feature *> list_t; + typedef list_t::iterator iterator; -private: - /** - * Set to true in case the matching feature was given as commandline - * argument. - */ - bool enabled_cmdline; - /** - * Set from the GUI options. This will not be set in case the GUI is - * not started at all. - */ - bool enabled_options; - - const std::string name; - const std::string description; + static const Feature ExperimentalConcatFunction; - typedef std::map<std::string, Feature *> map_t; - static map_t feature_map; - static list_t feature_list; + const std::string& get_name() const; + const std::string& get_description() const; - Feature(std::string name, std::string description); - virtual ~Feature(); - virtual void set_enable_cmdline(); - virtual void set_enable_options(bool status); + bool is_enabled() const; + void enable(bool status); -public: - static const Feature ExperimentalConcatFunction; + static iterator begin(); + static iterator end(); - const std::string& get_name() const; - const std::string& get_description() const; - - bool is_enabled() const; - void enable(bool status); + static void dump_features(); + static void enable_feature(const std::string &feature_name, bool status = true); - static iterator begin(); - static iterator end(); +private: + bool enabled; + + const std::string name; + const std::string description; + + typedef std::map<std::string, Feature *> map_t; + static map_t feature_map; + static list_t feature_list; - static void dump_features(); - static void enable_feature(std::string feature_name); - static void enable_feature(std::string feature_name, bool status); + Feature(const std::string &name, const std::string &description); + virtual ~Feature(); }; #endif diff --git a/src/openscad.cc b/src/openscad.cc index 574e87b..16a6e89 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -112,6 +112,7 @@ static void help(const char *progname) "%2% --camera=eyex,y,z,centerx,y,z ] \\\n" "%2%[ --imgsize=width,height ] [ --projection=(o)rtho|(p)ersp] \\\n" "%2%[ --render | --preview[=throwntogether] ] \\\n" + "%2%[ --enable=<feature> \\\n" "%2%filename\n", progname % (const char *)tabstr); exit(1); @@ -589,7 +590,7 @@ int main(int argc, char **argv) ("d,d", po::value<string>(), "deps-file") ("m,m", po::value<string>(), "makefile") ("D,D", po::value<vector<string> >(), "var=val") - ("enable-feature", po::value<vector<string> >(), "enable experimental features"); + ("enable", po::value<vector<string> >(), "enable experimental features"); po::options_description hidden("Hidden options"); hidden.add_options() @@ -653,8 +654,8 @@ int main(int argc, char **argv) commandline_commands += ";\n"; } } - if (vm.count("enable-feature")) { - BOOST_FOREACH(const string &feature, vm["enable-feature"].as<vector<string> >()) { + if (vm.count("enable")) { + BOOST_FOREACH(const string &feature, vm["enable"].as<vector<string> >()) { Feature::enable_feature(feature); } } |