Commit 965277e8 authored by Michael Reeves's avatar Michael Reeves

Finish moving optionItemList to Options class

parent 54e474be
Pipeline #8369 passed with stage
in 8 minutes and 27 seconds
......@@ -19,26 +19,31 @@
#include "options.h"
#include "ConfigValueMap.h"
#include "OptionItems.h"
void Options::init(std::list<OptionItemBase*> &optionItemList)
#include <KSharedConfig>
#define KDIFF3_CONFIG_GROUP "KDiff3 Options"
void Options::init()
{
/*
TODO manage toolbar positioning
*/
optionItemList.push_back(new OptionNum<int>( Qt::TopToolBarArea, "ToolBarPos", (int*)&m_toolBarPos));
optionItemList.push_back(new OptionSize(QSize(600, 400), "Geometry", &m_geometry));
optionItemList.push_back(new OptionPoint(QPoint(0, 22), "Position", &m_position));
optionItemList.push_back(new OptionToggleAction(false, "WindowStateMaximised", &m_bMaximised));
addOptionItem(new OptionNum<int>( Qt::TopToolBarArea, "ToolBarPos", (int*)&m_toolBarPos));
addOptionItem(new OptionSize(QSize(600, 400), "Geometry", &m_geometry));
addOptionItem(new OptionPoint(QPoint(0, 22), "Position", &m_position));
addOptionItem(new OptionToggleAction(false, "WindowStateMaximised", &m_bMaximised));
optionItemList.push_back(new OptionToggleAction(true, "Show Toolbar", &m_bShowToolBar));
optionItemList.push_back(new OptionToggleAction(true, "Show Statusbar", &m_bShowStatusBar));
addOptionItem(new OptionToggleAction(true, "Show Toolbar", &m_bShowToolBar));
addOptionItem(new OptionToggleAction(true, "Show Statusbar", &m_bShowStatusBar));
}
void Options::apply(const std::list<OptionItemBase*> &optionItemList)
void Options::apply()
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
for(i = mOptionItemList.begin(); i != mOptionItemList.end(); ++i)
{
(*i)->apply();
}
......@@ -54,20 +59,103 @@ void Options::apply(const std::list<OptionItemBase*> &optionItemList)
#endif
}
void Options::resetToDefaults(const std::list<OptionItemBase*> &optionItemList)
void Options::resetToDefaults()
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
for(i = mOptionItemList.begin(); i != mOptionItemList.end(); ++i)
{
(*i)->setToDefault();
}
}
void Options::setToCurrent(const std::list<OptionItemBase*> &optionItemList)
void Options::setToCurrent()
{
std::list<OptionItemBase*>::const_iterator i;
for(i = optionItemList.begin(); i != optionItemList.end(); ++i)
for(i = mOptionItemList.begin(); i != mOptionItemList.end(); ++i)
{
(*i)->setToCurrent();
}
}
void Options::saveOptions(const KSharedConfigPtr config)
{
// No i18n()-Translations here!
ConfigValueMap cvm(config->group(KDIFF3_CONFIG_GROUP));
std::list<OptionItemBase*>::const_iterator i;
for(i = mOptionItemList.begin(); i != mOptionItemList.end(); ++i)
{
(*i)->doUnpreserve();
(*i)->write(&cvm);
}
}
void Options::readOptions(const KSharedConfigPtr config)
{
// No i18n()-Translations here!
ConfigValueMap cvm(config->group(KDIFF3_CONFIG_GROUP));
std::list<OptionItemBase*>::const_iterator i;
for(i = mOptionItemList.begin(); i != mOptionItemList.end(); ++i)
{
(*i)->read(&cvm);
}
}
QString Options::parseOptions(const QStringList& optionList)
{
QString result;
QStringList::const_iterator i;
for(i = optionList.begin(); i != optionList.end(); ++i)
{
QString s = *i;
int pos = s.indexOf('=');
if(pos > 0) // seems not to have a tag
{
QString key = s.left(pos);
QString val = s.mid(pos + 1);
std::list<OptionItemBase*>::iterator j;
bool bFound = false;
for(j = mOptionItemList.begin(); j != mOptionItemList.end(); ++j)
{
if((*j)->getSaveName() == key)
{
(*j)->doPreserve();
ValueMap config;
config.writeEntry(key, val); // Write the value as a string and
(*j)->read(&config); // use the internal conversion from string to the needed value.
bFound = true;
break;
}
}
if(!bFound)
{
result += "No config item named \"" + key + "\"\n";
}
}
else
{
result += "No '=' found in \"" + s + "\"\n";
}
}
return result;
}
QString Options::calcOptionHelp()
{
ValueMap config;
std::list<OptionItemBase*>::const_iterator it;
for(it = mOptionItemList.begin(); it != mOptionItemList.end(); ++it)
{
(*it)->write(&config);
}
return config.getAsString();
}
void Options::addOptionItem(OptionItemBase* inItem)
{
mOptionItemList.push_back(inItem);
}
......@@ -20,7 +20,6 @@
*/
#include "optiondialog.h"
#include "OptionItems.h"
#include "ConfigValueMap.h"
#include "diff.h"
#include "smalldialogs.h"
......@@ -49,16 +48,12 @@
#include <QToolTip>
#include <KColorButton>
#include <KConfigGroup>
#include <KHelpClient>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSharedConfig>
#include <KToolBar>
#include <map>
#define KDIFF3_CONFIG_GROUP "KDiff3 Options"
QString s_historyEntryStartRegExpToolTip;
QString s_historyEntryStartSortKeyOrderToolTip;
QString s_autoMergeRegExpToolTip;
......@@ -482,7 +477,7 @@ class OptionEncodingComboBox : public QComboBox, public OptionCodec
void OptionDialog::addOptionItem(OptionItemBase* p)
{
m_optionItemList.push_back(p);
m_options->addOptionItem(p);
}
OptionDialog::OptionDialog(bool bShowDirMergeSettings, QWidget* parent) : KPageDialog(parent)
......@@ -496,7 +491,7 @@ OptionDialog::OptionDialog(bool bShowDirMergeSettings, QWidget* parent) : KPageD
//showButtonSeparator( true );
//setHelp( "kdiff3/index.html", QString::null );
m_options->init(m_optionItemList);
m_options->init();
setupFontPage();
setupColorPage();
setupEditPage();
......@@ -1561,7 +1556,7 @@ void OptionDialog::slotOk()
/** Copy the values from the widgets to the public variables.*/
void OptionDialog::slotApply()
{
m_options->apply(m_optionItemList);
m_options->apply();
emit applyDone();
}
......@@ -1579,14 +1574,14 @@ void OptionDialog::slotDefault()
void OptionDialog::resetToDefaults()
{
m_options->resetToDefaults(m_optionItemList);
m_options->resetToDefaults();
slotEncodingChanged();
}
/** Initialise the widgets using the values in the public varibles. */
void OptionDialog::setState()
{
m_options->setToCurrent(m_optionItemList);
m_options->setToCurrent();
slotEncodingChanged();
}
......@@ -1594,79 +1589,26 @@ void OptionDialog::setState()
void OptionDialog::saveOptions(KSharedConfigPtr config)
{
// No i18n()-Translations here!
ConfigValueMap cvm(config->group(KDIFF3_CONFIG_GROUP));
std::list<OptionItemBase*>::iterator i;
for(i = m_optionItemList.begin(); i != m_optionItemList.end(); ++i)
{
(*i)->doUnpreserve();
(*i)->write(&cvm);
}
m_options->saveOptions(config);
}
void OptionDialog::readOptions(KSharedConfigPtr config)
{
// No i18n()-Translations here!
ConfigValueMap cvm(config->group(KDIFF3_CONFIG_GROUP));
std::list<OptionItemBase*>::iterator i;
for(i = m_optionItemList.begin(); i != m_optionItemList.end(); ++i)
{
(*i)->read(&cvm);
}
m_options->readOptions(config);
setState();
}
QString OptionDialog::parseOptions(const QStringList& optionList)
{
QString result;
QStringList::const_iterator i;
for(i = optionList.begin(); i != optionList.end(); ++i)
{
QString s = *i;
int pos = s.indexOf('=');
if(pos > 0) // seems not to have a tag
{
QString key = s.left(pos);
QString val = s.mid(pos + 1);
std::list<OptionItemBase*>::iterator j;
bool bFound = false;
for(j = m_optionItemList.begin(); j != m_optionItemList.end(); ++j)
{
if((*j)->getSaveName() == key)
{
(*j)->doPreserve();
ValueMap config;
config.writeEntry(key, val); // Write the value as a string and
(*j)->read(&config); // use the internal conversion from string to the needed value.
bFound = true;
break;
}
}
if(!bFound)
{
result += "No config item named \"" + key + "\"\n";
}
}
else
{
result += "No '=' found in \"" + s + "\"\n";
}
}
return result;
return m_options->parseOptions(optionList);
}
QString OptionDialog::calcOptionHelp()
{
ValueMap config;
std::list<OptionItemBase*>::iterator j;
for(j = m_optionItemList.begin(); j != m_optionItemList.end(); ++j)
{
(*j)->write(&config);
}
return config.getAsString();
return m_options->calcOptionHelp();
}
void OptionDialog::slotHistoryMergeRegExpTester()
......
......@@ -88,8 +88,6 @@ private:
QSharedPointer<Options> m_options=QSharedPointer<Options>::create(Options());
std::list<OptionItemBase*> m_optionItemList;
//QDialogButtonBox *mButtonBox;
OptionCheckBox* m_pSameEncoding;
OptionEncodingComboBox* m_pEncodingAComboBox;
......
......@@ -21,14 +21,16 @@
#ifndef OPTIONS_H
#define OPTIONS_H
//#include <QToolBar>
#include <QStringList>
#include <QSize>
#include <QPoint>
#include <QFont>
#include <QColor>
#include <KSharedConfig>
#include <list>
#include <QColor>
#include <QFont>
#include <QPoint>
#include <QSize>
#include <QStringList>
class OptionItemBase;
enum e_LineEndStyle
......@@ -43,13 +45,23 @@ enum e_LineEndStyle
class Options
{
public:
void init(std::list<OptionItemBase*> &optionItemList);
void init();
void apply();
void resetToDefaults();
void apply(const std::list<OptionItemBase*> &optionItemList);
void setToCurrent();
void resetToDefaults(const std::list<OptionItemBase*> &optionItemList);
void saveOptions(const KSharedConfigPtr config);
void readOptions(const KSharedConfigPtr config);
QString parseOptions(const QStringList& optionList);
;
QString calcOptionHelp();
void addOptionItem(OptionItemBase* inItem);
void setToCurrent(const std::list<OptionItemBase*>& optionItemList);
const QSize& getGeometry() const { return m_geometry; }
void setGeometry(const QSize& size) { m_geometry = size; }
......@@ -67,10 +79,10 @@ public:
bool isStatusBarVisable() const { return m_bShowStatusBar; }
void setStatusBarState(bool inShown) { m_bShowStatusBar = inShown; }
private:
std::list<OptionItemBase*> mOptionItemList;
// Some settings are not available in the option dialog:
// Some settings that are not available in the option dialog:
QSize m_geometry = QSize(600, 400);
QPoint m_position = QPoint(0, 22);
bool m_bMaximised = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment