r22890 by jghali - Fix msvc warning about int <=> pointer conversion
scribus-commit
scribus-commit at lists.scribus.net
Tue Mar 12 12:59:37 UTC 2019
Author: jghali
Date: Tue Mar 12 12:59:37 2019
New Revision: 22890
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22890
Log:
Fix msvc warning about int <=> pointer conversion
Modified:
trunk/Scribus/scribus/pageitem.cpp
trunk/Scribus/scribus/undostate.cpp
trunk/Scribus/scribus/undostate.h
Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22890&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Tue Mar 12 12:59:37 2019
@@ -4638,7 +4638,7 @@
SimpleState *ss = new SimpleState(Um::ConvertTo + " " + toType,
QString(Um::FromTo).arg(fromType).arg(toType));
ss->set("CONVERT", "convert");
- ss->set("PAGEITEM", reinterpret_cast<int>(this));
+ ss->set("PAGEITEM", reinterpret_cast<void*>(this));
ss->set("OLD_TYPE", m_ItemType);
ss->set("NEW_TYPE", newType);
undoManager->action(this, ss);
@@ -7049,8 +7049,7 @@
// For now we'll just make it independent of 'this' -- AV
void PageItem::restoreType(SimpleState *state, bool isUndo)
{
- // well, probably not the best way to handle pointers...
- PageItem * item = reinterpret_cast<PageItem *>(state->getInt("PAGEITEM"));
+ PageItem * item = reinterpret_cast<PageItem *>(state->getVoidPtr("PAGEITEM"));
int type = state->getInt("OLD_TYPE");
if (!isUndo)
type = state->getInt("NEW_TYPE");
Modified: trunk/Scribus/scribus/undostate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22890&path=/trunk/Scribus/scribus/undostate.cpp
==============================================================================
--- trunk/Scribus/scribus/undostate.cpp (original)
+++ trunk/Scribus/scribus/undostate.cpp Tue Mar 12 12:59:37 2019
@@ -127,7 +127,7 @@
return def;
}
-int SimpleState::getInt(const QString& key, int def)
+bool SimpleState::getBool(const QString& key, bool def)
{
bool ok = false;
QVariant retVar = variant(key, QVariant(def));
@@ -137,6 +137,16 @@
return ret;
}
+int SimpleState::getInt(const QString& key, int def)
+{
+ bool ok = false;
+ QVariant retVar = variant(key, QVariant(def));
+ int ret = retVar.toInt(&ok);
+ if (!ok)
+ ret = def;
+ return ret;
+}
+
uint SimpleState::getUInt(const QString& key, uint def)
{
bool ok = false;
@@ -157,15 +167,15 @@
return ret;
}
-bool SimpleState::getBool(const QString& key, bool def)
-{
- bool ok = false;
- QVariant retVar = variant(key, QVariant(def));
- int ret = retVar.toInt(&ok);
- if (!ok)
- ret = def;
- return ret;
-}
+void* SimpleState::getVoidPtr(const QString& key, void* def)
+{
+ void* ret = nullptr;
+ QVariant retVar = variant(key, QVariant::fromValue(def));
+ if (!retVar.canConvert<void*>())
+ ret = retVar.value<void*>();
+ return ret;
+}
+
void SimpleState::set(const QString& key)
{
@@ -177,6 +187,11 @@
m_values[key] = QVariant(value);
}
+void SimpleState::set(const QString& key, bool value)
+{
+ m_values[key] = QVariant(value);
+}
+
void SimpleState::set(const QString& key, int value)
{
m_values[key] = QVariant(value);
@@ -192,11 +207,10 @@
m_values[key] = QVariant(value);
}
-void SimpleState::set(const QString& key, bool value)
-{
- m_values[key] = QVariant(value);
-}
-
+void SimpleState::set(const QString& key, void* ptr)
+{
+ m_values[key] = QVariant::fromValue<void*>(ptr);
+}
SimpleState::~SimpleState()
{
Modified: trunk/Scribus/scribus/undostate.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22890&path=/trunk/Scribus/scribus/undostate.h
==============================================================================
--- trunk/Scribus/scribus/undostate.h (original)
+++ trunk/Scribus/scribus/undostate.h Tue Mar 12 12:59:37 2019
@@ -244,6 +244,22 @@
bool getBool(const QString& key, bool def = false);
/**
+ * @brief Returns the pointer value attached to the key.
+ *
+ * Values are stored as <code>QString</code>s in the map and when queried
+ * with this method value attached to the key is converted to a void* pointer. If
+ * the conversion fails value of the parameter <code>def</code> will be returned.
+ * If key is not found from the map it will be added there with the
+ * value given as a parameter def. In such case <code>def</code> will also be returned.
+ * @param key Key that is searched from the map
+ * @param def Default value to be used if key is not found from the map
+ * @return <code>Double</code> value attached to the key in the map. If the key is not found
+ * from the map it will be added with the value described in the parameter
+ * <code>def</code> which is then returned.
+ */
+ void* getVoidPtr(const QString& key, void* def = nullptr);
+
+ /**
* @brief Set a key with no value, to be used only for configuring action type
* @param key Key that can be later used to query the value.
* @param value Value attached to the key.
@@ -284,6 +300,13 @@
* @param value Value attached to the key.
*/
void set(const QString& key, bool value);
+
+ /**
+ * @brief Set a value for the key.
+ * @param key Key that can be later used to query the value.
+ * @param value Value attached to the key.
+ */
+ void set(const QString& key, void* ptr);
private:
/** @brief QMap to store key-value pairs */
More information about the scribus-commit
mailing list