forked from teamnwah/openmw-tes3coop
Fixed broken delegate display modes (Display Format settings). Moved
UserSetting update functions to DataDisplayDelegate.
This commit is contained in:
parent
3f2ae950f5
commit
2e06414b43
10 changed files with 67 additions and 60 deletions
|
@ -338,5 +338,5 @@ void CSMSettings::SettingManager::updateUserSetting(const QString &settingKey,
|
|||
|
||||
setting->setDefinedValues (list);
|
||||
|
||||
emit userSettingUpdated (names.at(1), list);
|
||||
emit userSettingUpdated (settingKey, list);
|
||||
}
|
||||
|
|
|
@ -260,13 +260,16 @@ void CSMSettings::UserSettings::saveSettings
|
|||
writeFilestream (openFilestream (mUserFilePath, false), settingMap);
|
||||
}
|
||||
|
||||
QString CSMSettings::UserSettings::settingValue (const QString §ion,
|
||||
const QString &name)
|
||||
QString CSMSettings::UserSettings::settingValue (const QString &settingKey)
|
||||
{
|
||||
Setting *setting = findSetting(section, name);
|
||||
QStringList names = settingKey.split('.');
|
||||
qDebug () << "looking for " << names.at(0) << ',' << names.at(1);
|
||||
|
||||
Setting *setting = findSetting(names.at(0), names.at(1));
|
||||
|
||||
if (setting)
|
||||
{
|
||||
qDebug() << "setting found";
|
||||
if (!setting->definedValues().isEmpty())
|
||||
return setting->definedValues().at(0);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace CSMSettings {
|
|||
/// Writes settings to the user's config file path
|
||||
void saveSettings (const QMap <QString, QStringList > &settingMap);
|
||||
|
||||
QString settingValue (const QString §ion, const QString &name);
|
||||
QString settingValue (const QString &settingKey);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -236,10 +236,10 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
|||
mViewTotal (totalViews)
|
||||
{
|
||||
QString width = CSMSettings::UserSettings::instance().settingValue
|
||||
(QString("Window Size"), QString("Width"));
|
||||
("Window Size.Width");
|
||||
|
||||
QString height = CSMSettings::UserSettings::instance().settingValue
|
||||
(QString("Window Size"), QString("Height"));
|
||||
("Window Size.Height");
|
||||
|
||||
resize (width.toInt(), height.toInt());
|
||||
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
#include "datadisplaydelegate.hpp"
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values,
|
||||
const IconList &icons,
|
||||
QUndoStack &undoStack, QObject *parent)
|
||||
: EnumDelegate (values, undoStack, parent), mDisplayMode (Mode_TextOnly), mIcons (icons)
|
||||
, mIconSize (QSize(16, 16)), mIconLeftOffset(3), mTextLeftOffset(8)
|
||||
QUndoStack &undoStack,
|
||||
const QString &settingKey,
|
||||
QObject *parent)
|
||||
: EnumDelegate (values, undoStack, parent), mDisplayMode (Mode_TextOnly),
|
||||
mIcons (icons), mIconSize (QSize(16, 16)), mIconLeftOffset(3),
|
||||
mTextLeftOffset(8), mSettingKey (settingKey)
|
||||
{
|
||||
mTextAlignment.setAlignment (Qt::AlignLeft | Qt::AlignVCenter );
|
||||
|
||||
buildPixmaps();
|
||||
|
||||
QString value =
|
||||
CSMSettings::UserSettings::instance().settingValue (settingKey);
|
||||
|
||||
updateDisplayMode(value);
|
||||
}
|
||||
|
||||
void CSVWorld::DataDisplayDelegate::buildPixmaps ()
|
||||
|
@ -89,6 +99,30 @@ void CSVWorld::DataDisplayDelegate::paintIcon (QPainter *painter, const QStyleOp
|
|||
painter->drawPixmap (iconRect, mPixmaps.at(index).second);
|
||||
}
|
||||
|
||||
void CSVWorld::DataDisplayDelegate::updateUserSetting (const QString &name,
|
||||
const QStringList &list)
|
||||
{
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
QString value = list.at(0);
|
||||
|
||||
if (name == mSettingKey)
|
||||
updateDisplayMode (value);
|
||||
}
|
||||
|
||||
void CSVWorld::DataDisplayDelegate::updateDisplayMode (const QString &mode)
|
||||
{
|
||||
if (mode == "Icon and Text")
|
||||
mDisplayMode = Mode_IconAndText;
|
||||
|
||||
else if (mode == "Icon Only")
|
||||
mDisplayMode = Mode_IconOnly;
|
||||
|
||||
else if (mode == "Text Only")
|
||||
mDisplayMode = Mode_TextOnly;
|
||||
}
|
||||
|
||||
CSVWorld::DataDisplayDelegate::~DataDisplayDelegate()
|
||||
{
|
||||
mIcons.clear();
|
||||
|
@ -106,5 +140,7 @@ CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate (Q
|
|||
QObject *parent) const
|
||||
{
|
||||
|
||||
return new DataDisplayDelegate (mValues, mIcons, undoStack, parent);
|
||||
return new DataDisplayDelegate (mValues, mIcons, undoStack, "", parent);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,10 +35,14 @@ namespace CSVWorld
|
|||
int mIconLeftOffset;
|
||||
int mTextLeftOffset;
|
||||
|
||||
QString mSettingKey;
|
||||
|
||||
public:
|
||||
explicit DataDisplayDelegate (const ValueList & values,
|
||||
const IconList & icons,
|
||||
QUndoStack& undoStack, QObject *parent);
|
||||
QUndoStack& undoStack,
|
||||
const QString &settingKey,
|
||||
QObject *parent);
|
||||
|
||||
~DataDisplayDelegate();
|
||||
|
||||
|
@ -53,8 +57,14 @@ namespace CSVWorld
|
|||
/// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels.
|
||||
void setTextLeftOffset (int offset);
|
||||
|
||||
///update the display mode for the delegate
|
||||
void updateUserSetting (const QString &name, const QStringList &list);
|
||||
|
||||
private:
|
||||
|
||||
/// update the display mode based on a passed string
|
||||
void updateDisplayMode (const QString &);
|
||||
|
||||
/// custom paint function for painting the icon. Mode_IconAndText and Mode_Icon only.
|
||||
void paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int i) const;
|
||||
|
||||
|
|
|
@ -4,30 +4,11 @@
|
|||
|
||||
CSVWorld::IdTypeDelegate::IdTypeDelegate
|
||||
(const ValueList &values, const IconList &icons, QUndoStack& undoStack, QObject *parent)
|
||||
: DataDisplayDelegate (values, icons, undoStack, parent)
|
||||
: DataDisplayDelegate (values, icons, undoStack,
|
||||
"Display Format.Referenceable ID Type Display",
|
||||
parent)
|
||||
{}
|
||||
|
||||
bool CSVWorld::IdTypeDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
/// \todo make the setting key a member variable, that is initialised from a constructor argument
|
||||
if (settingName == "Referenceable ID Type Display")
|
||||
{
|
||||
if (settingValue == "Icon and Text")
|
||||
mDisplayMode = Mode_IconAndText;
|
||||
|
||||
else if (settingValue == "Icon Only")
|
||||
mDisplayMode = Mode_IconOnly;
|
||||
|
||||
else if (settingValue == "Text Only")
|
||||
mDisplayMode = Mode_TextOnly;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
CSVWorld::IdTypeDelegateFactory::IdTypeDelegateFactory()
|
||||
{
|
||||
for (int i=0; i<CSMWorld::UniversalId::NumberOfTypes; ++i)
|
||||
|
|
|
@ -12,9 +12,6 @@ namespace CSVWorld
|
|||
{
|
||||
public:
|
||||
IdTypeDelegate (const ValueList &mValues, const IconList &icons, QUndoStack& undoStack, QObject *parent);
|
||||
|
||||
virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
||||
};
|
||||
|
||||
class IdTypeDelegateFactory : public DataDisplayDelegateFactory
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values,
|
||||
const IconList & icons,
|
||||
QUndoStack &undoStack, QObject *parent)
|
||||
: DataDisplayDelegate (values, icons, undoStack, parent)
|
||||
: DataDisplayDelegate (values, icons, undoStack,
|
||||
"Display Format.Record Status Display",
|
||||
parent)
|
||||
{}
|
||||
|
||||
CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (QUndoStack& undoStack,
|
||||
|
@ -19,25 +21,6 @@ CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (
|
|||
return new RecordStatusDelegate (mValues, mIcons, undoStack, parent);
|
||||
}
|
||||
|
||||
bool CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
if (settingName == "Record Status Display")
|
||||
{
|
||||
if (settingValue == "Icon and Text")
|
||||
mDisplayMode = Mode_IconAndText;
|
||||
|
||||
else if (settingValue == "Icon Only")
|
||||
mDisplayMode = Mode_IconOnly;
|
||||
|
||||
else if (settingValue == "Text Only")
|
||||
mDisplayMode = Mode_TextOnly;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory()
|
||||
{
|
||||
std::vector<std::string> enums =
|
||||
|
|
|
@ -20,9 +20,6 @@ namespace CSVWorld
|
|||
explicit RecordStatusDelegate(const ValueList& values,
|
||||
const IconList& icons,
|
||||
QUndoStack& undoStack, QObject *parent = 0);
|
||||
|
||||
virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue);
|
||||
|
||||
};
|
||||
|
||||
class RecordStatusDelegateFactory : public DataDisplayDelegateFactory
|
||||
|
|
Loading…
Reference in a new issue