Merge branch 'master' into bug1196jumpdialog
Conflicts: apps/openmw/mwinput/inputmanagerimp.cppdeque
commit
bbb7ceab43
@ -0,0 +1,130 @@
|
||||
|
||||
#include "loader.hpp"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "../tools/reportmodel.hpp"
|
||||
|
||||
#include "document.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
CSMDoc::Loader::Stage::Stage() : mFile (0), mRecordsLeft (false) {}
|
||||
|
||||
|
||||
CSMDoc::Loader::Loader()
|
||||
{
|
||||
QTimer *timer = new QTimer (this);
|
||||
|
||||
connect (timer, SIGNAL (timeout()), this, SLOT (load()));
|
||||
timer->start();
|
||||
}
|
||||
|
||||
QWaitCondition& CSMDoc::Loader::hasThingsToDo()
|
||||
{
|
||||
return mThingsToDo;
|
||||
}
|
||||
|
||||
void CSMDoc::Loader::load()
|
||||
{
|
||||
if (mDocuments.empty())
|
||||
{
|
||||
mMutex.lock();
|
||||
mThingsToDo.wait (&mMutex);
|
||||
mMutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::pair<Document *, Stage> >::iterator iter = mDocuments.begin();
|
||||
|
||||
Document *document = iter->first;
|
||||
|
||||
int size = static_cast<int> (document->getContentFiles().size());
|
||||
|
||||
if (document->isNew())
|
||||
--size;
|
||||
|
||||
bool done = false;
|
||||
|
||||
const int batchingSize = 100;
|
||||
|
||||
try
|
||||
{
|
||||
if (iter->second.mRecordsLeft)
|
||||
{
|
||||
CSMDoc::Stage::Messages messages;
|
||||
for (int i=0; i<batchingSize; ++i) // do not flood the system with update signals
|
||||
if (document->getData().continueLoading (messages))
|
||||
{
|
||||
iter->second.mRecordsLeft = false;
|
||||
break;
|
||||
}
|
||||
|
||||
CSMWorld::UniversalId log (CSMWorld::UniversalId::Type_LoadErrorLog, 0);
|
||||
|
||||
for (CSMDoc::Stage::Messages::const_iterator iter (messages.begin());
|
||||
iter!=messages.end(); ++iter)
|
||||
{
|
||||
document->getReport (log)->add (iter->first, iter->second);
|
||||
emit loadMessage (document, iter->second);
|
||||
}
|
||||
|
||||
emit nextRecord (document);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (iter->second.mFile<size)
|
||||
{
|
||||
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
||||
|
||||
int steps = document->getData().startLoading (path, iter->second.mFile<size-1, false);
|
||||
iter->second.mRecordsLeft = true;
|
||||
|
||||
emit nextStage (document, path.filename().string(), steps/batchingSize);
|
||||
}
|
||||
else if (iter->second.mFile==size)
|
||||
{
|
||||
int steps = document->getData().startLoading (document->getProjectPath(), false, true);
|
||||
iter->second.mRecordsLeft = true;
|
||||
|
||||
emit nextStage (document, "Project File", steps/batchingSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
|
||||
++(iter->second.mFile);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
mDocuments.erase (iter);
|
||||
emit documentNotLoaded (document, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
mDocuments.erase (iter);
|
||||
emit documentLoaded (document);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
|
||||
{
|
||||
mDocuments.push_back (std::make_pair (document, Stage()));
|
||||
}
|
||||
|
||||
void CSMDoc::Loader::abortLoading (CSMDoc::Document *document)
|
||||
{
|
||||
for (std::vector<std::pair<Document *, Stage> >::iterator iter = mDocuments.begin();
|
||||
iter!=mDocuments.end(); ++iter)
|
||||
{
|
||||
if (iter->first==document)
|
||||
{
|
||||
mDocuments.erase (iter);
|
||||
emit documentNotLoaded (document, "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
#ifndef CSM_DOC_LOADER_H
|
||||
#define CSM_DOC_LOADER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
|
||||
class Loader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
struct Stage
|
||||
{
|
||||
int mFile;
|
||||
bool mRecordsLeft;
|
||||
|
||||
Stage();
|
||||
};
|
||||
|
||||
QMutex mMutex;
|
||||
QWaitCondition mThingsToDo;
|
||||
std::vector<std::pair<Document *, Stage> > mDocuments;
|
||||
|
||||
public:
|
||||
|
||||
Loader();
|
||||
|
||||
QWaitCondition& hasThingsToDo();
|
||||
|
||||
private slots:
|
||||
|
||||
void load();
|
||||
|
||||
public slots:
|
||||
|
||||
void loadDocument (CSMDoc::Document *document);
|
||||
///< The ownership of \a document is not transferred.
|
||||
|
||||
void abortLoading (CSMDoc::Document *document);
|
||||
///< Abort loading \a docuemnt (ignored if \a document has already finished being
|
||||
/// loaded). Will result in a documentNotLoaded signal, once the Loader has finished
|
||||
/// cleaning up.
|
||||
|
||||
signals:
|
||||
|
||||
void documentLoaded (Document *document);
|
||||
///< The ownership of \a document is not transferred.
|
||||
|
||||
void documentNotLoaded (Document *document, const std::string& error);
|
||||
///< Document load has been interrupted either because of a call to abortLoading
|
||||
/// or a problem during loading). In the former case error will be an empty string.
|
||||
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||
|
||||
void nextRecord (CSMDoc::Document *document);
|
||||
///< \note This signal is only given once per group of records. The group size is
|
||||
/// approximately the total number of records divided by the steps value of the
|
||||
/// previous nextStage signal.
|
||||
|
||||
void loadMessage (CSMDoc::Document *document, const std::string& message);
|
||||
///< Non-critical load error or warning
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,128 @@
|
||||
#include "connector.hpp"
|
||||
#include "../../view/settings/view.hpp"
|
||||
#include "../../view/settings/page.hpp"
|
||||
|
||||
CSMSettings::Connector::Connector(CSVSettings::View *master,
|
||||
QObject *parent)
|
||||
: mMasterView (master), QObject(parent)
|
||||
{}
|
||||
|
||||
void CSMSettings::Connector::addSlaveView (CSVSettings::View *view,
|
||||
QList <QStringList> &masterProxyValues)
|
||||
{
|
||||
mSlaveViews.append (view);
|
||||
|
||||
mProxyListMap[view->viewKey()].append (masterProxyValues);
|
||||
}
|
||||
|
||||
QList <QStringList> CSMSettings::Connector::getSlaveViewValues() const
|
||||
{
|
||||
QList <QStringList> list;
|
||||
|
||||
foreach (const CSVSettings::View *view, mSlaveViews)
|
||||
list.append (view->selectedValues());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool CSMSettings::Connector::proxyListsMatch (
|
||||
const QList <QStringList> &list1,
|
||||
const QList <QStringList> &list2) const
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
for (int i = 0; i < list1.size(); i++)
|
||||
{
|
||||
success = stringListsMatch (list1.at(i), list2.at(i));
|
||||
|
||||
if (!success)
|
||||
break;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void CSMSettings::Connector::slotUpdateMaster() const
|
||||
{
|
||||
//list of the current values for each slave.
|
||||
QList <QStringList> slaveValueList = getSlaveViewValues();
|
||||
|
||||
int masterColumn = -1;
|
||||
|
||||
/*
|
||||
* A row in the master view is one of the values in the
|
||||
* master view's data model. This corresponds directly to the number of
|
||||
* values in a proxy list contained in the ProxyListMap member.
|
||||
* Thus, we iterate each "column" in the master proxy list
|
||||
* (one for each vlaue in the master. Each column represents
|
||||
* one master value's corresponding list of slave values. We examine
|
||||
* each master value's list, comparing it to the current slave value list,
|
||||
* stopping when we find a match using proxyListsMatch().
|
||||
*
|
||||
* If no match is found, clear the master view's value
|
||||
*/
|
||||
|
||||
for (int i = 0; i < mMasterView->rowCount(); i++)
|
||||
{
|
||||
QList <QStringList> proxyValueList;
|
||||
|
||||
foreach (const QString &settingKey, mProxyListMap.keys())
|
||||
{
|
||||
// append the proxy value list stored in the i'th column
|
||||
// for each setting key. A setting key is the id of the setting
|
||||
// in page.name format.
|
||||
proxyValueList.append (mProxyListMap.value(settingKey).at(i));
|
||||
}
|
||||
|
||||
if (proxyListsMatch (slaveValueList, proxyValueList))
|
||||
{
|
||||
masterColumn = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString masterValue = mMasterView->value (masterColumn);
|
||||
|
||||
mMasterView->setSelectedValue (masterValue);
|
||||
}
|
||||
|
||||
void CSMSettings::Connector::slotUpdateSlaves() const
|
||||
{
|
||||
int row = mMasterView->currentIndex();
|
||||
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
//iterate the proxy lists for the chosen master index
|
||||
//and pass the list to each slave for updating
|
||||
for (int i = 0; i < mSlaveViews.size(); i++)
|
||||
{
|
||||
QList <QStringList> proxyList =
|
||||
mProxyListMap.value(mSlaveViews.at(i)->viewKey());
|
||||
|
||||
mSlaveViews.at(i)->setSelectedValues (proxyList.at(row));
|
||||
}
|
||||
}
|
||||
|
||||
bool CSMSettings::Connector::stringListsMatch (
|
||||
const QStringList &list1,
|
||||
const QStringList &list2) const
|
||||
{
|
||||
//returns a "sloppy" match, verifying that each list contains all the same
|
||||
//items, though not necessarily in the same order.
|
||||
|
||||
if (list1.size() != list2.size())
|
||||
return false;
|
||||
|
||||
QStringList tempList(list2);
|
||||
|
||||
//iterate each value in the list, removing one occurrence of the value in
|
||||
//the other list. If no corresponding value is found, test fails
|
||||
foreach (const QString &value, list1)
|
||||
{
|
||||
if (!tempList.contains(value))
|
||||
return false;
|
||||
|
||||
tempList.removeOne(value);
|
||||
}
|
||||
return true;
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
#ifndef CSMSETTINGS_CONNECTOR_HPP
|
||||
#define CSMSETTINGS_CONNECTOR_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
#include "support.hpp"
|
||||
|
||||
namespace CSVSettings {
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace CSMSettings {
|
||||
|
||||
class Connector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSVSettings::View *mMasterView;
|
||||
|
||||
///map using the view pointer as a key to it's index value
|
||||
QList <CSVSettings::View *> mSlaveViews;
|
||||
|
||||
///list of proxy values for each master value.
|
||||
///value list order is indexed to the master value index.
|
||||
QMap < QString, QList <QStringList> > mProxyListMap;
|
||||
|
||||
public:
|
||||
explicit Connector(CSVSettings::View *master,
|
||||
QObject *parent = 0);
|
||||
|
||||
///Set the view which acts as a proxy for other setting views
|
||||
void setMasterView (CSVSettings::View *view);
|
||||
|
||||
///Add a view to be updated / update to the master
|
||||
void addSlaveView (CSVSettings::View *view,
|
||||
QList <QStringList> &masterProxyValues);
|
||||
|
||||
private:
|
||||
|
||||
///loosely matches lists of proxy values across registered slaves
|
||||
///against a proxy value list for a given master value
|
||||
bool proxyListsMatch (const QList <QStringList> &list1,
|
||||
const QList <QStringList> &list2) const;
|
||||
|
||||
///loosely matches two string lists
|
||||
bool stringListsMatch (const QStringList &list1,
|
||||
const QStringList &list2) const;
|
||||
|
||||
///retrieves current values of registered slave views
|
||||
QList <QStringList> getSlaveViewValues() const;
|
||||
|
||||
public slots:
|
||||
|
||||
///updates slave views with proxy values associated with current
|
||||
///master value
|
||||
void slotUpdateSlaves() const;
|
||||
|
||||
///updates master value associated with the currently selected
|
||||
///slave values, if applicable.
|
||||
void slotUpdateMaster() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSMSETTINGS_CONNECTOR_HPP
|
@ -0,0 +1,391 @@
|
||||
#include "setting.hpp"
|
||||
#include "support.hpp"
|
||||
|
||||
CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
|
||||
const QString &pageName)
|
||||
: mIsEditorSetting (false)
|
||||
{
|
||||
buildDefaultSetting();
|
||||
|
||||
int settingType = static_cast <int> (typ);
|
||||
|
||||
//even-numbered setting types are multi-valued
|
||||
if ((settingType % 2) == 0)
|
||||
setProperty (Property_IsMultiValue, QVariant(true).toString());
|
||||
|
||||
//view type is related to setting type by an order of magnitude
|
||||
setProperty (Property_SettingType, QVariant (settingType).toString());
|
||||
setProperty (Property_Page, pageName);
|
||||
setProperty (Property_Name, settingName);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::buildDefaultSetting()
|
||||
{
|
||||
int arrLen = sizeof(sPropertyDefaults) / sizeof (*sPropertyDefaults);
|
||||
|
||||
for (int i = 0; i < arrLen; i++)
|
||||
{
|
||||
QStringList propertyList;
|
||||
|
||||
if (i <Property_DefaultValues)
|
||||
propertyList.append (sPropertyDefaults[i]);
|
||||
|
||||
mProperties.append (propertyList);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::addProxy (const Setting *setting,
|
||||
const QStringList &vals)
|
||||
{
|
||||
if (serializable())
|
||||
setSerializable (false);
|
||||
|
||||
QList <QStringList> list;
|
||||
|
||||
foreach (const QString &val, vals)
|
||||
list << (QStringList() << val);
|
||||
|
||||
mProxies [setting->page() + '/' + setting->name()] = list;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::addProxy (const Setting *setting,
|
||||
const QList <QStringList> &list)
|
||||
{
|
||||
if (serializable())
|
||||
setProperty (Property_Serializable, false);
|
||||
|
||||
mProxies [setting->page() + '/' + setting->name()] = list;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setColumnSpan (int value)
|
||||
{
|
||||
setProperty (Property_ColumnSpan, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::columnSpan() const
|
||||
{
|
||||
return property (Property_ColumnSpan).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDeclaredValues (QStringList list)
|
||||
{
|
||||
setProperty (Property_DeclaredValues, list);
|
||||
}
|
||||
|
||||
QStringList CSMSettings::Setting::declaredValues() const
|
||||
{
|
||||
return property (Property_DeclaredValues);
|
||||
}
|
||||
|
||||
QStringList CSMSettings::Setting::property (SettingProperty prop) const
|
||||
{
|
||||
if (prop >= mProperties.size())
|
||||
return QStringList();
|
||||
|
||||
return mProperties.at(prop);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDefaultValue (int value)
|
||||
{
|
||||
setDefaultValues (QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDefaultValue (double value)
|
||||
{
|
||||
setDefaultValues (QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDefaultValue (const QString &value)
|
||||
{
|
||||
setDefaultValues (QStringList() << value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDefaultValues (const QStringList &values)
|
||||
{
|
||||
setProperty (Property_DefaultValues, values);
|
||||
}
|
||||
|
||||
QStringList CSMSettings::Setting::defaultValues() const
|
||||
{
|
||||
return property (Property_DefaultValues);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDelimiter (const QString &value)
|
||||
{
|
||||
setProperty (Property_Delimiter, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::delimiter() const
|
||||
{
|
||||
return property (Property_Delimiter).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setEditorSetting(bool state)
|
||||
{
|
||||
mIsEditorSetting = true;
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isEditorSetting() const
|
||||
{
|
||||
return mIsEditorSetting;
|
||||
}
|
||||
void CSMSettings::Setting::setIsMultiLine (bool state)
|
||||
{
|
||||
setProperty (Property_IsMultiLine, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isMultiLine() const
|
||||
{
|
||||
return (property (Property_IsMultiLine).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setIsMultiValue (bool state)
|
||||
{
|
||||
setProperty (Property_IsMultiValue, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isMultiValue() const
|
||||
{
|
||||
return (property (Property_IsMultiValue).at(0) == "true");
|
||||
}
|
||||
|
||||
const CSMSettings::ProxyValueMap &CSMSettings::Setting::proxyLists() const
|
||||
{
|
||||
return mProxies;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSerializable (bool state)
|
||||
{
|
||||
setProperty (Property_Serializable, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::serializable() const
|
||||
{
|
||||
return (property (Property_Serializable).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSpecialValueText(const QString &text)
|
||||
{
|
||||
setProperty (Property_SpecialValueText, text);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::specialValueText() const
|
||||
{
|
||||
return property (Property_SpecialValueText).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setName (const QString &value)
|
||||
{
|
||||
setProperty (Property_Name, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::name() const
|
||||
{
|
||||
return property (Property_Name).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setPage (const QString &value)
|
||||
{
|
||||
setProperty (Property_Page, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::page() const
|
||||
{
|
||||
return property (Property_Page).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setPrefix (const QString &value)
|
||||
{
|
||||
setProperty (Property_Prefix, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::prefix() const
|
||||
{
|
||||
return property (Property_Prefix).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setRowSpan (const int value)
|
||||
{
|
||||
setProperty (Property_RowSpan, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::rowSpan () const
|
||||
{
|
||||
return property (Property_RowSpan).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSingleStep (int value)
|
||||
{
|
||||
setProperty (Property_SingleStep, value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSingleStep (double value)
|
||||
{
|
||||
setProperty (Property_SingleStep, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::singleStep() const
|
||||
{
|
||||
return property (Property_SingleStep).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSuffix (const QString &value)
|
||||
{
|
||||
setProperty (Property_Suffix, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::suffix() const
|
||||
{
|
||||
return property (Property_Suffix).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setTickInterval (int value)
|
||||
{
|
||||
setProperty (Property_TickInterval, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::tickInterval () const
|
||||
{
|
||||
return property (Property_TickInterval).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setTicksAbove (bool state)
|
||||
{
|
||||
setProperty (Property_TicksAbove, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::ticksAbove() const
|
||||
{
|
||||
return (property (Property_TicksAbove).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setTicksBelow (bool state)
|
||||
{
|
||||
setProperty (Property_TicksBelow, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::ticksBelow() const
|
||||
{
|
||||
return (property (Property_TicksBelow).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setType (int settingType)
|
||||
{
|
||||
setProperty (Property_SettingType, settingType);
|
||||
}
|
||||
|
||||
CSMSettings::SettingType CSMSettings::Setting::type() const
|
||||
{
|
||||
return static_cast <CSMSettings::SettingType> ( property (
|
||||
Property_SettingType).at(0).toInt());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setMaximum (int value)
|
||||
{
|
||||
setProperty (Property_Maximum, value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setMaximum (double value)
|
||||
{
|
||||
setProperty (Property_Maximum, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::maximum() const
|
||||
{
|
||||
return property (Property_Maximum).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setMinimum (int value)
|
||||
{
|
||||
setProperty (Property_Minimum, value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setMinimum (double value)
|
||||
{
|
||||
setProperty (Property_Minimum, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::minimum() const
|
||||
{
|
||||
return property (Property_Minimum).at(0);
|
||||
}
|
||||
|
||||
CSVSettings::ViewType CSMSettings::Setting::viewType() const
|
||||
{
|
||||
return static_cast <CSVSettings::ViewType> ( property (
|
||||
Property_SettingType).at(0).toInt() / 10);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewColumn (int value)
|
||||
{
|
||||
setProperty (Property_ViewColumn, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::viewColumn() const
|
||||
{
|
||||
return property (Property_ViewColumn).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewLocation (int row, int column)
|
||||
{
|
||||
setViewRow (row);
|
||||
setViewColumn (column);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewRow (int value)
|
||||
{
|
||||
setProperty (Property_ViewRow, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::viewRow() const
|
||||
{
|
||||
return property (Property_ViewRow).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setWidgetWidth (int value)
|
||||
{
|
||||
setProperty (Property_WidgetWidth, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::widgetWidth() const
|
||||
{
|
||||
return property (Property_WidgetWidth).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setWrapping (bool state)
|
||||
{
|
||||
setProperty (Property_Wrapping, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::wrapping() const
|
||||
{
|
||||
return (property (Property_Wrapping).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop, bool value)
|
||||
{
|
||||
setProperty (prop, QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop, int value)
|
||||
{
|
||||
setProperty (prop, QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop, double value)
|
||||
{
|
||||
setProperty (prop, QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop,
|
||||
const QString &value)
|
||||
{
|
||||
setProperty (prop, QStringList() << value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop,
|
||||
const QStringList &value)
|
||||
{
|
||||
if (prop < mProperties.size())
|
||||
mProperties.replace (prop, value);
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
#ifndef CSMSETTINGS_SETTING_HPP
|
||||
#define CSMSETTINGS_SETTING_HPP
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include "support.hpp"
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
//QString is the setting id in the form of "page/name"
|
||||
//QList is a list of stringlists of proxy values.
|
||||
//Order is important! Proxy stringlists are matched against
|
||||
//master values by their position in the QList.
|
||||
typedef QMap <QString, QList <QStringList> > ProxyValueMap;
|
||||
|
||||
///Setting class is the interface for the User Settings. It contains
|
||||
///a great deal of boiler plate to provide the core API functions, as
|
||||
///well as the property() functions which use enumeration to be iterable.
|
||||
///This makes the Setting class capable of being manipulated by script.
|
||||
///See CSMSettings::support.hpp for enumerations / string values.
|
||||
class Setting
|
||||
{
|
||||
QList <QStringList> mProperties;
|
||||
QStringList mDefaults;
|
||||
|
||||
bool mIsEditorSetting;
|
||||
|
||||
ProxyValueMap mProxies;
|
||||
|
||||
public:
|
||||
|
||||
explicit Setting(SettingType typ, const QString &settingName,
|
||||
const QString &pageName);
|
||||
|
||||
void addProxy (const Setting *setting, const QStringList &vals);
|
||||
void addProxy (const Setting *setting, const QList <QStringList> &list);
|
||||
|
||||
const QList <QStringList> &properties() const { return mProperties; }
|
||||
const ProxyValueMap &proxies() const { return mProxies; }
|
||||
|
||||
void setColumnSpan (int value);
|
||||
int columnSpan() const;
|
||||
|
||||
void setDeclaredValues (QStringList list);
|
||||
QStringList declaredValues() const;
|
||||
|
||||
void setDefaultValue (int value);
|
||||
void setDefaultValue (double value);
|
||||
void setDefaultValue (const QString &value);
|
||||
|
||||
void setDefaultValues (const QStringList &values);
|
||||
QStringList defaultValues() const;
|
||||
|
||||
void setDelimiter (const QString &value);
|
||||
QString delimiter() const;
|
||||
|
||||
void setEditorSetting (bool state);
|
||||
bool isEditorSetting() const;
|
||||
|
||||
void setIsMultiLine (bool state);
|
||||
bool isMultiLine() const;
|
||||
|
||||
void setIsMultiValue (bool state);
|
||||
bool isMultiValue() const;
|
||||
|
||||
void setMask (const QString &value);
|
||||
QString mask() const;
|
||||
|
||||
void setMaximum (int value);
|
||||
void setMaximum (double value);
|
||||
QString maximum() const;
|
||||
|
||||
void setMinimum (int value);
|
||||
void setMinimum (double value);
|
||||
QString minimum() const;
|
||||
|
||||
void setName (const QString &value);
|
||||
QString name() const;
|
||||
|
||||
void setPage (const QString &value);
|
||||
QString page() const;
|
||||
|
||||
void setPrefix (const QString &value);
|
||||
QString prefix() const;
|
||||
|
||||
void setRowSpan (const int value);
|
||||
int rowSpan() const;
|
||||
|
||||
const ProxyValueMap &proxyLists() const;
|
||||
|
||||
void setSerializable (bool state);
|
||||
bool serializable() const;
|
||||
|
||||
void setSpecialValueText (const QString &text);
|
||||
QString specialValueText() const;
|
||||
|
||||
void setSingleStep (int value);
|
||||
void setSingleStep (double value);
|
||||
QString singleStep() const;
|
||||
|
||||
void setSuffix (const QString &value);
|
||||
QString suffix() const;
|
||||
|
||||
void setTickInterval (int value);
|
||||
int tickInterval() const;
|
||||
|
||||
void setTicksAbove (bool state);
|
||||
bool ticksAbove() const;
|
||||
|
||||
void setTicksBelow (bool state);
|
||||
bool ticksBelow() const;
|
||||
|
||||
void setViewColumn (int value);
|
||||
int viewColumn() const;
|
||||
|
||||
void setViewLocation (int row = -1, int column = -1);
|
||||
|
||||
void setViewRow (int value);
|
||||
int viewRow() const;
|
||||
|
||||
void setType (int settingType);
|
||||
CSMSettings::SettingType type() const;
|
||||
|
||||
CSVSettings::ViewType viewType() const;
|
||||
|
||||
void setWrapping (bool state);
|
||||
bool wrapping() const;
|
||||
|
||||
void setWidgetWidth (int value);
|
||||
int widgetWidth() const;
|
||||
|
||||
///returns the specified property value
|
||||
QStringList property (SettingProperty prop) const;
|
||||
|
||||
///boilerplate code to convert setting values of common types
|
||||
void setProperty (SettingProperty prop, bool value);
|
||||
void setProperty (SettingProperty prop, int value);
|
||||
void setProperty (SettingProperty prop, double value);
|
||||
void setProperty (SettingProperty prop, const QString &value);
|
||||
void setProperty (SettingProperty prop, const QStringList &value);
|
||||
|
||||
void addProxy (Setting* setting,
|
||||
QMap <QString, QStringList> &proxyMap);
|
||||
|
||||
protected:
|
||||
void buildDefaultSetting();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSMSETTINGS_SETTING_HPP
|
@ -1,82 +0,0 @@
|
||||
#include "settingcontainer.hpp"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
CSMSettings::SettingContainer::SettingContainer(QObject *parent) :
|
||||
QObject(parent), mValue (0), mValues (0)
|
||||
{
|
||||
}
|
||||
|
||||
CSMSettings::SettingContainer::SettingContainer(const QString &value, QObject *parent) :
|
||||
QObject(parent), mValue (new QString (value)), mValues (0)
|
||||
{
|
||||
}
|
||||
|
||||
void CSMSettings::SettingContainer::insert (const QString &value)
|
||||
{
|
||||
if (mValue)
|
||||
{
|
||||
mValues = new QStringList;
|
||||
mValues->push_back (*mValue);
|
||||
mValues->push_back (value);
|
||||
|
||||
delete mValue;
|
||||
mValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete mValue;
|
||||
mValue = new QString (value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CSMSettings::SettingContainer::update (const QString &value, int index)
|
||||
{
|
||||
if (isEmpty())
|
||||
mValue = new QString(value);
|
||||
|
||||
else if (mValue)
|
||||
*mValue = value;
|
||||
|
||||
else if (mValues)
|
||||
mValues->replace(index, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::SettingContainer::getValue (int index) const
|
||||
{
|
||||
QString retVal("");
|
||||
|
||||
//if mValue is valid, it's a single-value property.
|
||||
//ignore the index and return the value
|
||||
if (mValue)
|
||||
retVal = *mValue;
|
||||
|
||||
//otherwise, if it's a multivalued property
|
||||
//return the appropriate value at the index
|
||||
else if (mValues)
|
||||
{
|
||||
if (index == -1)
|
||||
retVal = mValues->at(0);
|
||||
|
||||
else if (index < mValues->size())
|
||||
retVal = mValues->at(index);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int CSMSettings::SettingContainer::count () const
|
||||
{
|
||||
int retVal = 0;
|
||||
|
||||
if (!isEmpty())
|
||||
{
|
||||
if (mValues)
|
||||
retVal = mValues->size();
|
||||
else
|
||||
retVal = 1;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#ifndef SETTINGCONTAINER_HPP
|
||||
#define SETTINGCONTAINER_HPP
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QStringList;
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
class SettingContainer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QString *mValue;
|
||||
QStringList *mValues;
|
||||
|
||||
public:
|
||||
|
||||
explicit SettingContainer (QObject *parent = 0);
|
||||
explicit SettingContainer (const QString &value, QObject *parent = 0);
|
||||
|
||||
/// add a value to the container
|
||||
/// multiple values supported
|
||||
void insert (const QString &value);
|
||||
|
||||
/// update an existing value
|
||||
/// index specifies multiple values
|
||||
void update (const QString &value, int index = 0);
|
||||
|
||||
/// return value at specified index
|
||||
QString getValue (int index = -1) const;
|
||||
|
||||
/// retrieve list of all values
|
||||
inline QStringList *getValues() const { return mValues; }
|
||||
|
||||
/// return size of list
|
||||
int count() const;
|
||||
|
||||
/// test for empty container
|
||||
/// useful for default-constructed containers returned by QMap when invalid key is passed
|
||||
inline bool isEmpty() const { return (!mValue && !mValues); }
|
||||
|
||||
inline bool isMultiValue() const { return (mValues); }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SETTINGCONTAINER_HPP
|
@ -1,104 +0,0 @@
|
||||
#include "settingsitem.hpp"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
bool CSMSettings::SettingsItem::updateItem (const QStringList *values)
|
||||
{
|
||||
QStringList::ConstIterator it = values->begin();
|
||||
|
||||
//if the item is not multivalued,
|
||||
//save the last value passed in the container
|
||||
if (!mIsMultiValue)
|
||||
{
|
||||
it = values->end();
|
||||
it--;
|
||||
}
|
||||
|
||||
bool isValid = true;
|
||||
QString value ("");
|
||||
|
||||
for (; it != values->end(); ++it)
|
||||
{
|
||||
value = *it;
|
||||
isValid = validate(value);
|
||||
|
||||
//skip only the invalid values
|
||||
if (!isValid)
|
||||
continue;
|
||||
|
||||
insert(value);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
bool CSMSettings::SettingsItem::updateItem (const QString &value)
|
||||
{
|
||||
//takes a value or a SettingsContainer and updates itself accordingly
|
||||
//after validating the data against it's own definition
|
||||
|
||||
QString newValue = value;
|
||||
|
||||
if (!validate (newValue))
|
||||
newValue = mDefaultValue;
|
||||
|
||||
bool success = (getValue() != newValue);
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (mIsMultiValue)
|
||||
insert (newValue);
|
||||
else
|
||||
update (newValue);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CSMSettings::SettingsItem::updateItem(int valueListIndex)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
if (mValueList)
|
||||
{
|
||||
if (mValueList->size() > valueListIndex)
|
||||
success = updateItem (mValueList->at(valueListIndex));
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CSMSettings::SettingsItem::validate (const QString &value)
|
||||
{
|
||||
//if there is no value list or value pair, there is no validation to do
|
||||
bool isValid = !(!mValueList->isEmpty() || mValuePair);
|
||||
|
||||
if (!isValid && !mValueList->isEmpty())
|
||||
{
|
||||
for (QStringList::Iterator it = mValueList->begin(); it != mValueList->end(); ++it)
|
||||
// foreach (QString listItem, *mValueList)
|
||||
{
|
||||
isValid = (value == *it);
|
||||
|
||||
if (isValid)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!isValid && mValuePair)
|
||||
{
|
||||
int numVal = value.toInt();
|
||||
|
||||
isValid = (numVal > mValuePair->left.toInt() && numVal < mValuePair->right.toInt());
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
void CSMSettings::SettingsItem::setDefaultValue (const QString &value)
|
||||
{
|
||||
mDefaultValue = value;
|
||||
update (value);
|
||||
}
|
||||
|
||||
QString CSMSettings::SettingsItem::getDefaultValue() const
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
#ifndef SETTINGSITEM_HPP
|
||||
#define SETTINGSITEM_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include "support.hpp"
|
||||
#include "settingcontainer.hpp"
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
/// Represents a setting including metadata
|
||||
/// (valid values, ranges, defaults, and multivalue status
|
||||
class SettingsItem : public SettingContainer
|
||||
{
|
||||
QStringPair *mValuePair;
|
||||
QStringList *mValueList;
|
||||
bool mIsMultiValue;
|
||||
QString mDefaultValue;
|
||||
|
||||
public:
|
||||
explicit SettingsItem(QString name, bool isMultiValue,
|
||||
const QString& defaultValue, QObject *parent = 0)
|
||||
: SettingContainer(defaultValue, parent),
|
||||
mIsMultiValue (isMultiValue), mValueList (0),
|
||||
mValuePair (0), mDefaultValue (defaultValue)
|
||||
{
|
||||
QObject::setObjectName(name);
|
||||
}
|
||||
|
||||
/// updateItem overloads for updating setting value
|
||||
/// provided a list of values (multi-valued),
|
||||
/// a specific value
|
||||
/// or an index value corresponding to the mValueList
|
||||
bool updateItem (const QStringList *values);
|
||||
bool updateItem (const QString &value);
|
||||
bool updateItem (int valueListIndex);
|
||||
|
||||
/// retrieve list of valid values for setting
|
||||
inline QStringList *getValueList() { return mValueList; }
|
||||
|
||||
/// write list of valid values for setting
|
||||
inline void setValueList (QStringList *valueList) { mValueList = valueList; }
|
||||
|
||||
/// valuePair used for spin boxes (max / min)
|
||||
inline QStringPair *getValuePair() { return mValuePair; }
|
||||
|
||||
/// set value range (spinbox / integer use)
|
||||
inline void setValuePair (QStringPair valuePair)
|
||||
{
|
||||
delete mValuePair;
|
||||
mValuePair = new QStringPair(valuePair);
|
||||
}
|
||||
|
||||
inline bool isMultivalue () { return mIsMultiValue; }
|
||||
|
||||
void setDefaultValue (const QString &value);
|
||||
QString getDefaultValue () const;
|
||||
|
||||
private:
|
||||
|
||||
/// Verifies that the supplied value is one of the following:
|
||||
/// 1. Within the limits of the value pair (min / max)
|
||||
/// 2. One of the values indicated in the value list
|
||||
bool validate (const QString &value);
|
||||
};
|
||||
}
|
||||
#endif // SETTINGSITEM_HPP
|
||||
|
@ -1 +0,0 @@
|
||||
#include "support.hpp"
|
@ -1,39 +1,145 @@
|
||||
#ifndef MODEL_SUPPORT_HPP
|
||||
#define MODEL_SUPPORT_HPP
|
||||
#ifndef SETTING_SUPPORT_HPP
|
||||
#define SETTING_SUPPORT_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <Qt>
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
|
||||
class QLayout;
|
||||
class QWidget;
|
||||
class QListWidgetItem;
|
||||
|
||||
//Enums
|
||||
namespace CSMSettings
|
||||
{
|
||||
class SettingContainer;
|
||||
///Enumerated properties for scripting
|
||||
enum SettingProperty
|
||||
{
|
||||
Property_Name = 0,
|
||||
Property_Page = 1,
|
||||
Property_SettingType = 2,
|
||||
Property_IsMultiValue = 3,
|
||||
Property_IsMultiLine = 4,
|
||||
Property_WidgetWidth = 5,
|
||||
Property_ViewRow = 6,
|
||||
Property_ViewColumn = 7,
|
||||
Property_Delimiter = 8,
|
||||
Property_Serializable = 9,
|
||||
Property_ColumnSpan = 10,
|
||||
Property_RowSpan = 11,
|
||||
Property_Minimum = 12,
|
||||
Property_Maximum = 13,
|
||||
Property_SpecialValueText = 14,
|
||||
Property_Prefix = 15,
|
||||
Property_Suffix = 16,
|
||||
Property_SingleStep = 17,
|
||||
Property_Wrapping = 18,
|
||||
Property_TickInterval = 19,
|
||||
Property_TicksAbove = 20,
|
||||
Property_TicksBelow = 21,
|
||||
|
||||
//Stringlists should always be the last items
|
||||
Property_DefaultValues = 22,
|
||||
Property_DeclaredValues = 23,
|
||||
Property_DefinedValues = 24,
|
||||
Property_Proxies = 25
|
||||
};
|
||||
|
||||
///Basic setting widget types.
|
||||
enum SettingType
|
||||
{
|
||||
/*
|
||||
* 0 - 9 - Boolean widgets
|
||||
* 10-19 - List widgets
|
||||
* 21-29 - Range widgets
|
||||
* 31-39 - Text widgets
|
||||
*
|
||||
* Each range corresponds to a View_Type enum by a factor of 10.
|
||||
*
|
||||
* Even-numbered values are single-value widgets
|
||||
* Odd-numbered values are multi-valued widgets
|
||||
*/
|
||||
|
||||
typedef QList<SettingContainer *> SettingList;
|
||||
typedef QMap<QString, SettingContainer *> SettingMap;
|
||||
typedef QMap<QString, SettingMap *> SectionMap;
|
||||
Type_CheckBox = 0,
|
||||
Type_RadioButton = 1,
|
||||
Type_ListView = 10,
|
||||
Type_ComboBox = 11,
|
||||
Type_SpinBox = 21,
|
||||
Type_DoubleSpinBox = 23,
|
||||
Type_Slider = 25,
|
||||
Type_Dial = 27,
|
||||
Type_TextArea = 30,
|
||||
Type_LineEdit = 31,
|
||||
Type_Undefined = 40
|
||||
};
|
||||
|
||||
struct QStringPair
|
||||
}
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
///Categorical view types which encompass the setting widget types
|
||||
enum ViewType
|
||||
{
|
||||
QStringPair(): left (""), right ("")
|
||||
{}
|
||||
ViewType_Boolean = 0,
|
||||
ViewType_List = 1,
|
||||
ViewType_Range = 2,
|
||||
ViewType_Text = 3,
|
||||
ViewType_Undefined = 4
|
||||
};
|
||||
}
|
||||
|
||||
QStringPair (const QString &leftValue, const QString &rightValue)
|
||||
: left (leftValue), right(rightValue)
|
||||
{}
|
||||
|
||||
QStringPair (const QStringPair &pair)
|
||||
: left (pair.left), right (pair.right)
|
||||
{}
|
||||
namespace CSMSettings
|
||||
{
|
||||
///used to construct default settings in the Setting class
|
||||
struct PropertyDefaultValues
|
||||
{
|
||||
int id;
|
||||
QString name;
|
||||
QVariant value;
|
||||
};
|
||||
|
||||
QString left;
|
||||
QString right;
|
||||
///strings which correspond to setting values. These strings represent
|
||||
///the script language keywords which would be used to declare setting
|
||||
///views for 3rd party addons
|
||||
const QString sPropertyNames[] =
|
||||
{
|
||||
"name", "page", "setting_type", "is_multi_value",
|
||||
"is_multi_line", "widget_width", "view_row", "view_column", "delimiter",
|
||||
"is_serializable","column_span", "row_span", "minimum", "maximum",
|
||||
"special_value_text", "prefix", "suffix", "single_step", "wrapping",
|
||||
"tick_interval", "ticks_above", "ticks_below",
|
||||
"defaults", "declarations", "definitions", "proxies"
|
||||
};
|
||||
|
||||
bool isEmpty() const
|
||||
{ return (left.isEmpty() && right.isEmpty()); }
|
||||
///Default values for a setting. Used in setting creation.
|
||||
const QString sPropertyDefaults[] =
|
||||
{
|
||||
"", //name
|
||||
"", //page
|
||||
"40", //setting type
|
||||
"false", //multivalue
|
||||
"false", //multiline
|
||||
"7", //widget width
|
||||
"-1", //view row
|
||||
"-1", //view column
|
||||
",", //delimiter
|
||||
"true", //serialized
|
||||
"1", //column span
|
||||
"1", //row span
|
||||
"0", //value range
|
||||
"0", //value minimum
|
||||
"0", //value maximum
|
||||
"", //special text
|
||||
"", //prefix
|
||||
"", //suffix
|
||||
"false", //wrapping
|
||||
"1", //tick interval
|
||||
"false", //ticks above
|
||||
"true", //ticks below
|
||||
"", //default values
|
||||
"", //declared values
|
||||
"", //defined values
|
||||
"" //proxy values
|
||||
};
|
||||
}
|
||||
#endif // MODEL_SUPPORT_HPP
|
||||
|
||||
#endif // VIEW_SUPPORT_HPP
|
||||
|
@ -1,12 +1,10 @@
|
||||
|
||||
#include "ref.hpp"
|
||||
|
||||
#include "cell.hpp"
|
||||
|
||||
void CSMWorld::CellRef::load (ESM::ESMReader &esm, Cell& cell, const std::string& id)
|
||||
CSMWorld::CellRef::CellRef()
|
||||
{
|
||||
mId = id;
|
||||
mCell = cell.mId;
|
||||
mRefNum.mIndex = 0;
|
||||
|
||||
cell.addRef (mId);
|
||||
// special marker: This reference does not have a RefNum assign to it yet.
|
||||
mRefNum.mContentFile = -2;
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
|
||||
#include "loader.hpp"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QCursor>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QListWidget>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
cancel();
|
||||
}
|
||||
|
||||
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||
: mDocument (document), mAborted (false), mMessages (0)
|
||||
{
|
||||
setWindowTitle (("Opening " + document->getSavePath().filename().string()).c_str());
|
||||
|
||||
setMinimumWidth (400);
|
||||
|
||||
mLayout = new QVBoxLayout (this);
|
||||
|
||||
// file progress
|
||||
mFile = new QLabel (this);
|
||||
|
||||
mLayout->addWidget (mFile);
|
||||
|
||||
mFileProgress = new QProgressBar (this);
|
||||
|
||||
mLayout->addWidget (mFileProgress);
|
||||
|
||||
int size = static_cast<int> (document->getContentFiles().size())+1;
|
||||
if (document->isNew())
|
||||
--size;
|
||||
|
||||
mFileProgress->setMinimum (0);
|
||||
mFileProgress->setMaximum (size);
|
||||
mFileProgress->setTextVisible (true);
|
||||
mFileProgress->setValue (0);
|
||||
|
||||
// record progress
|
||||
mLayout->addWidget (new QLabel ("Records", this));
|
||||
|
||||
mRecordProgress = new QProgressBar (this);
|
||||
|
||||
mLayout->addWidget (mRecordProgress);
|
||||
|
||||
mRecordProgress->setMinimum (0);
|
||||
mRecordProgress->setTextVisible (true);
|
||||
mRecordProgress->setValue (0);
|
||||
|
||||
// error message
|
||||
mError = new QLabel (this);
|
||||
mError->setWordWrap (true);
|
||||
|
||||
mLayout->addWidget (mError);
|
||||
|
||||
// buttons
|
||||
mButtons = new QDialogButtonBox (QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
|
||||
mLayout->addWidget (mButtons);
|
||||
|
||||
setLayout (mLayout);
|
||||
|
||||
move (QCursor::pos());
|
||||
|
||||
show();
|
||||
|
||||
connect (mButtons, SIGNAL (rejected()), this, SLOT (cancel()));
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
||||
{
|
||||
mFile->setText (QString::fromUtf8 (("Loading: " + name).c_str()));
|
||||
|
||||
mFileProgress->setValue (mFileProgress->value()+1);
|
||||
|
||||
mRecordProgress->setValue (0);
|
||||
mRecordProgress->setMaximum (steps>0 ? steps : 1);
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::nextRecord()
|
||||
{
|
||||
int value = mRecordProgress->value()+1;
|
||||
|
||||
if (value<=mRecordProgress->maximum())
|
||||
mRecordProgress->setValue (value);
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::abort (const std::string& error)
|
||||
{
|
||||
mAborted = true;
|
||||
mError->setText (QString::fromUtf8 (("Loading failed: " + error).c_str()));
|
||||
mButtons->setStandardButtons (QDialogButtonBox::Close);
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::addMessage (const std::string& message)
|
||||
{
|
||||
if (!mMessages)
|
||||
{
|
||||
mMessages = new QListWidget (this);
|
||||
mLayout->insertWidget (4, mMessages);
|
||||
}
|
||||
|
||||
new QListWidgetItem (QString::fromUtf8 (message.c_str()), mMessages);
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::cancel()
|
||||
{
|
||||
if (!mAborted)
|
||||
emit cancel (mDocument);
|
||||
else
|
||||
{
|
||||
emit close (mDocument);
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CSVDoc::Loader::Loader() {}
|
||||
|
||||
CSVDoc::Loader::~Loader()
|
||||
{
|
||||
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
||||
iter!=mDocuments.end(); ++iter)
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::add (CSMDoc::Document *document)
|
||||
{
|
||||
LoadingDocument *loading = new LoadingDocument (document);
|
||||
mDocuments.insert (std::make_pair (document, loading));
|
||||
|
||||
connect (loading, SIGNAL (cancel (CSMDoc::Document *)),
|
||||
this, SIGNAL (cancel (CSMDoc::Document *)));
|
||||
connect (loading, SIGNAL (close (CSMDoc::Document *)),
|
||||
this, SIGNAL (close (CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,
|
||||
const std::string& error)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.begin();
|
||||
|
||||
for (; iter!=mDocuments.end(); ++iter)
|
||||
if (iter->first==document)
|
||||
break;
|
||||
|
||||
if (iter==mDocuments.end())
|
||||
return;
|
||||
|
||||
if (completed || error.empty())
|
||||
{
|
||||
delete iter->second;
|
||||
mDocuments.erase (iter);
|
||||
}
|
||||
else if (!completed && !error.empty())
|
||||
{
|
||||
iter->second->abort (error);
|
||||
// Leave the window open for now (wait for the user to close it)
|
||||
mDocuments.erase (iter);
|
||||
}
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::nextStage (CSMDoc::Document *document, const std::string& name, int steps)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||
|
||||
if (iter!=mDocuments.end())
|
||||
iter->second->nextStage (name, steps);
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::nextRecord (CSMDoc::Document *document)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||
|
||||
if (iter!=mDocuments.end())
|
||||
iter->second->nextRecord();
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::loadMessage (CSMDoc::Document *document, const std::string& message)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||
|
||||
if (iter!=mDocuments.end())
|
||||
iter->second->addMessage (message);
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
#ifndef CSV_DOC_LOADER_H
|
||||
#define CSV_DOC_LOADER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QSignalMapper>
|
||||
|
||||
class QLabel;
|
||||
class QProgressBar;
|
||||
class QDialogButtonBox;
|
||||
class QListWidget;
|
||||
class QVBoxLayout;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class LoadingDocument : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMDoc::Document *mDocument;
|
||||
QLabel *mFile;
|
||||
QProgressBar *mFileProgress;
|
||||
QProgressBar *mRecordProgress;
|
||||
bool mAborted;
|
||||
QDialogButtonBox *mButtons;
|
||||
QLabel *mError;
|
||||
QListWidget *mMessages;
|
||||
QVBoxLayout *mLayout;
|
||||
|
||||
private:
|
||||
|
||||
void closeEvent (QCloseEvent *event);
|
||||
|
||||
public:
|
||||
|
||||
LoadingDocument (CSMDoc::Document *document);
|
||||
|
||||
void nextStage (const std::string& name, int steps);
|
||||
|
||||
void nextRecord();
|
||||
|
||||
void abort (const std::string& error);
|
||||
|
||||
void addMessage (const std::string& message);
|
||||
|
||||
private slots:
|
||||
|
||||
void cancel();
|
||||
|
||||
signals:
|
||||
|
||||
void cancel (CSMDoc::Document *document);
|
||||
///< Stop loading process.
|
||||
|
||||
void close (CSMDoc::Document *document);
|
||||
///< Close stopped loading process.
|
||||
};
|
||||
|
||||
class Loader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
std::map<CSMDoc::Document *, LoadingDocument *> mDocuments;
|
||||
|
||||
public:
|
||||
|
||||
Loader();
|
||||
|
||||
virtual ~Loader();
|
||||
|
||||
signals:
|
||||
|
||||
void cancel (CSMDoc::Document *document);
|
||||
|
||||
void close (CSMDoc::Document *document);
|
||||
|
||||
public slots:
|
||||
|
||||
void add (CSMDoc::Document *document);
|
||||
|
||||
void loadingStopped (CSMDoc::Document *document, bool completed,
|
||||
const std::string& error);
|
||||
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||
|
||||
void nextRecord (CSMDoc::Document *document);
|
||||
|
||||
void loadMessage (CSMDoc::Document *document, const std::string& message);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,62 +0,0 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include <components/fileorderlist/datafileslist.hpp>
|
||||
|
||||
#include "opendialog.hpp"
|
||||
|
||||
OpenDialog::OpenDialog(QWidget * parent) : QDialog(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
mFileSelector = new DataFilesList(mCfgMgr, this);
|
||||
layout->addWidget(mFileSelector);
|
||||
|
||||
/// \todo move config to Editor class and add command line options.
|
||||
// We use the Configuration Manager to retrieve the configuration values
|
||||
boost::program_options::variables_map variables;
|
||||
boost::program_options::options_description desc;
|
||||
|
||||
desc.add_options()
|
||||
("data", boost::program_options::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken())
|
||||
("data-local", boost::program_options::value<std::string>()->default_value(""))
|
||||
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
|
||||
("encoding", boost::program_options::value<std::string>()->default_value("win1252"));
|
||||
|
||||
boost::program_options::notify(variables);
|
||||
|
||||
mCfgMgr.readConfiguration(variables, desc);
|
||||
|
||||
Files::PathContainer mDataDirs, mDataLocal;
|
||||
if (!variables["data"].empty()) {
|
||||
mDataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
||||
}
|
||||
|
||||
std::string local = variables["data-local"].as<std::string>();
|
||||
if (!local.empty()) {
|
||||
mDataLocal.push_back(Files::PathContainer::value_type(local));
|
||||
}
|
||||
|
||||
mCfgMgr.processPaths(mDataDirs);
|
||||
mCfgMgr.processPaths(mDataLocal);
|
||||
|
||||
// Set the charset for reading the esm/esp files
|
||||
QString encoding = QString::fromUtf8 (variables["encoding"].as<std::string>().c_str());
|
||||
|
||||
Files::PathContainer dataDirs;
|
||||
dataDirs.insert(dataDirs.end(), mDataDirs.begin(), mDataDirs.end());
|
||||
dataDirs.insert(dataDirs.end(), mDataLocal.begin(), mDataLocal.end());
|
||||
mFileSelector->setupDataFiles(dataDirs, encoding);
|
||||
|
||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
layout->addWidget(buttonBox);
|
||||
|
||||
setLayout(layout);
|
||||
setWindowTitle(tr("Open"));
|
||||
}
|
||||
|
||||
void OpenDialog::getFileList(std::vector<boost::filesystem::path>& paths)
|
||||
{
|
||||
mFileSelector->selectedFiles(paths);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#include <qdialog.h>
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
|
||||
class DataFilesList;
|
||||
class QDialogButtonBox;
|
||||
|
||||
class OpenDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OpenDialog(QWidget * parent = 0);
|
||||
|
||||
void getFileList(std::vector<boost::filesystem::path>& paths);
|
||||
private:
|
||||
DataFilesList * mFileSelector;
|
||||
QDialogButtonBox * buttonBox;
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue