Added GUI for cache size adjustment

felipesanches-svg
Marius Kintel 2012-01-10 00:55:46 +01:00
parent a4810e0019
commit 5c999479a3
4 changed files with 145 additions and 61 deletions

View File

@ -39,21 +39,6 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
setupUi(this);
// Editor pane
QFontDatabase db;
foreach(int size, db.standardSizes()) {
this->fontSize->addItem(QString::number(size));
if (size == 12) {
this->fontSize->setCurrentIndex(this->fontSize->count()-1);
}
}
// Setup default settings
this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text();
this->defaultmap["advanced/opencsg_show_warning"] = true;
this->defaultmap["advanced/enable_opencsg_opengl1x"] = true;
this->defaultmap["caches/polysetCacheSize"] = uint(PolySetCache::instance()->maxSize());
this->defaultmap["caches/cgalCacheSize"] = uint(CGALCache::instance()->maxSize());
// Setup default font (Try to use a nice monospace font)
QString fontfamily;
#ifdef Q_WS_X11
@ -70,6 +55,23 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->defaultmap["editor/fontfamily"] = found_family;
this->defaultmap["editor/fontsize"] = 12;
QFontDatabase db;
foreach(int size, db.standardSizes()) {
this->fontSize->addItem(QString::number(size));
if (size == 12) {
this->fontSize->setCurrentIndex(this->fontSize->count()-1);
}
}
// Setup default settings
this->defaultmap["3dview/colorscheme"] = this->colorSchemeChooser->currentItem()->text();
this->defaultmap["advanced/opencsg_show_warning"] = true;
this->defaultmap["advanced/enable_opencsg_opengl1x"] = true;
this->defaultmap["advanced/polysetCacheSize"] = uint(PolySetCache::instance()->maxSize());
this->defaultmap["advanced/cgalCacheSize"] = uint(CGALCache::instance()->maxSize());
this->defaultmap["advanced/openCSGLimit"] = 2000;
// Toolbar
QActionGroup *group = new QActionGroup(this);
group->addAction(prefsAction3DView);
@ -114,14 +116,12 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
this->colorschemes["Sunset"][RenderSettings::CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
connect(this->colorSchemeChooser, SIGNAL(itemSelectionChanged()),
this, SLOT(colorSchemeChanged()));
connect(this->fontChooser, SIGNAL(activated(const QString &)),
this, SLOT(fontFamilyChanged(const QString &)));
connect(this->fontSize, SIGNAL(editTextChanged(const QString &)),
this, SLOT(fontSizeChanged(const QString &)));
connect(this->openCSGWarningBox, SIGNAL(toggled(bool)),
this, SLOT(openCSGWarningChanged(bool)));
// Advanced pane
QValidator *validator = new QIntValidator(this);
this->cgalCacheSizeEdit->setValidator(validator);
this->polysetCacheSizeEdit->setValidator(validator);
this->opencsgLimitEdit->setValidator(validator);
updateGUI();
RenderSettings::inst()->setColors(this->colorschemes[getValue("3dview/colorscheme").toString()]);
@ -146,7 +146,7 @@ Preferences::actionTriggered(QAction *action)
}
}
void Preferences::colorSchemeChanged()
void Preferences::on_colorSchemeChooser_itemSelectionChanged()
{
QString scheme = this->colorSchemeChooser->currentItem()->text();
QSettings settings;
@ -157,14 +157,14 @@ void Preferences::colorSchemeChanged()
emit requestRedraw();
}
void Preferences::fontFamilyChanged(const QString &family)
void Preferences::on_fontChooser_activated(const QString &family)
{
QSettings settings;
settings.setValue("editor/fontfamily", family);
emit fontChanged(family, getValue("editor/fontsize").toUInt());
}
void Preferences::fontSizeChanged(const QString &size)
void Preferences::on_fontSize_editTextChanged(const QString &size)
{
uint intsize = size.toUInt();
QSettings settings;
@ -173,19 +173,40 @@ void Preferences::fontSizeChanged(const QString &size)
}
void
Preferences::openCSGWarningChanged(bool state)
Preferences::on_openCSGWarningBox_toggled(bool state)
{
QSettings settings;
settings.setValue("advanced/opencsg_show_warning",state);
}
void
Preferences::enableOpenCSGChanged(bool state)
Preferences::on_enableOpenCSGBox_toggled(bool state)
{
QSettings settings;
settings.setValue("advanced/enable_opencsg_opengl1x", state);
}
void Preferences::on_cgalCacheSizeEdit_textChanged(const QString &text)
{
QSettings settings;
settings.setValue("advanced/cgalCacheSize", text);
CGALCache::instance()->setMaxSize(text.toULong());
}
void Preferences::on_polysetCacheSizeEdit_textChanged(const QString &text)
{
QSettings settings;
settings.setValue("advanced/polysetCacheSize", text);
PolySetCache::instance()->setMaxSize(text.toULong());
}
void Preferences::on_opencsgLimitEdit_textChanged(const QString &text)
{
QSettings settings;
settings.setValue("advanced/openCSGLimit", text);
// FIXME: Set this globally?
}
void Preferences::keyPressEvent(QKeyEvent *e)
{
#ifdef Q_WS_MAC
@ -218,6 +239,7 @@ void Preferences::removeDefaultSettings()
QVariant Preferences::getValue(const QString &key) const
{
QSettings settings;
assert(settings.contains(key) || this->defaultmap.contains(key));
return settings.value(key, this->defaultmap[key]);
}
@ -246,6 +268,9 @@ void Preferences::updateGUI()
this->openCSGWarningBox->setChecked(getValue("advanced/opencsg_show_warning").toBool());
this->enableOpenCSGBox->setChecked(getValue("advanced/enable_opencsg_opengl1x").toBool());
this->cgalCacheSizeEdit->setText(getValue("advanced/cgalCacheSize").toString());
this->polysetCacheSizeEdit->setText(getValue("advanced/polysetCacheSize").toString());
this->opencsgLimitEdit->setText(getValue("advanced/openCSGLimit").toString());
}
void Preferences::apply() const

View File

@ -19,11 +19,14 @@ public:
public slots:
void actionTriggered(class QAction *);
void colorSchemeChanged();
void fontFamilyChanged(const QString &);
void fontSizeChanged(const QString &);
void openCSGWarningChanged(bool);
void enableOpenCSGChanged(bool);
void on_colorSchemeChooser_itemSelectionChanged();
void on_fontChooser_activated(const QString &);
void on_fontSize_editTextChanged(const QString &);
void on_openCSGWarningBox_toggled(bool);
void on_enableOpenCSGBox_toggled(bool);
void on_cgalCacheSizeEdit_textChanged(const QString &);
void on_polysetCacheSizeEdit_textChanged(const QString &);
void on_opencsgLimitEdit_textChanged(const QString &);
signals:
void requestRedraw() const;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>418</width>
<height>243</height>
<height>269</height>
</rect>
</property>
<property name="windowTitle">
@ -175,43 +175,99 @@
</widget>
<widget class="QWidget" name="pageAdvanced">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<widget class="QCheckBox" name="openCSGWarningBox">
<property name="text">
<string>Show OpenCSG capability warning</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableOpenCSGBox">
<property name="text">
<string>Enable OpenCSG for OpenGL 1.x</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="openCSGWarningBox">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Show OpenCSG capability warning</string>
</property>
<property name="checked">
<bool>true</bool>
<string>CGAL Cache size</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableOpenCSGBox">
<property name="text">
<string>Enable OpenCSG for OpenGL 1.x</string>
</property>
</widget>
<widget class="QLineEdit" name="cgalCacheSizeEdit"/>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QLabel" name="label_2">
<property name="text">
<string>bytes</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>PolySet Cache size</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="polysetCacheSizeEdit"/>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>bytes</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Turn off OpenCSG rendering at </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="opencsgLimitEdit"/>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>elements</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>11</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>

View File

@ -411,9 +411,9 @@ MainWindow::loadDesignSettings()
if (settings.value("design/autoReload").toBool()) {
designActionAutoReload->setChecked(true);
}
uint polySetCacheSize = Preferences::inst()->getValue("caches/polysetCacheSize").toUInt();
uint polySetCacheSize = Preferences::inst()->getValue("advanced/polysetCacheSize").toUInt();
PolySetCache::instance()->setMaxSize(polySetCacheSize);
uint cgalCacheSize = Preferences::inst()->getValue("caches/cgalCacheSize").toUInt();
uint cgalCacheSize = Preferences::inst()->getValue("advanced/cgalCacheSize").toUInt();
CGALCache::instance()->setMaxSize(cgalCacheSize);
}
@ -804,7 +804,7 @@ void MainWindow::compileCSG(bool procevents)
}
}
if (root_chain->polysets.size() > 1000) {
if (root_chain->polysets.size() > Preferences::inst()->getValue("advanced/openCSGLimit").toUInt()) {
PRINTF("WARNING: Normalized tree has %d elements!", int(root_chain->polysets.size()));
PRINTF("WARNING: OpenCSG rendering has been disabled.");
}