r22694 by jghali - refactoring and warning fixes for undo classes

scribus-commit scribus-commit at lists.scribus.net
Sun Sep 16 11:50:19 UTC 2018


Author: jghali
Date: Sun Sep 16 11:50:19 2018
New Revision: 22694

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22694
Log:
refactoring and warning fixes for undo classes

Modified:
    trunk/Scribus/scribus/undomanager.cpp
    trunk/Scribus/scribus/undostate.cpp
    trunk/Scribus/scribus/undostate.h

Modified: trunk/Scribus/scribus/undomanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22694&path=/trunk/Scribus/scribus/undomanager.cpp
==============================================================================
--- trunk/Scribus/scribus/undomanager.cpp	(original)
+++ trunk/Scribus/scribus/undomanager.cpp	Sun Sep 16 11:50:19 2018
@@ -277,7 +277,7 @@
 		stacks_[currentDoc_] = UndoStack();
 
 	stacks_[currentDoc_].setMaxSize(prefs_->getInt("historylength", 100));
-	for (int i = 0; i < undoGuis_.size(); ++i)
+	for (size_t i = 0; i < undoGuis_.size(); ++i)
 		setState(undoGuis_[i]);
 
 	setTexts();
@@ -307,7 +307,7 @@
 		stacks_.remove(stackName);
 		if (currentDoc_ == stackName)
 		{
-			for (int i = 0; i < undoGuis_.size(); ++i)
+			for (size_t i = 0; i < undoGuis_.size(); ++i)
 				undoGuis_[i]->clear();
 			currentDoc_ = "__no_name__";
 		}
@@ -317,7 +317,7 @@
 void UndoManager::clearStack()
 {
 	stacks_[currentDoc_].clear();
-	for (int i = 0; i < undoGuis_.size(); ++i)
+	for (size_t i = 0; i < undoGuis_.size(); ++i)
 	{
 		undoGuis_[i]->clear();
 		setState(undoGuis_[i]);

Modified: trunk/Scribus/scribus/undostate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22694&path=/trunk/Scribus/scribus/undostate.cpp
==============================================================================
--- trunk/Scribus/scribus/undostate.cpp	(original)
+++ trunk/Scribus/scribus/undostate.cpp	Sun Sep 16 11:50:19 2018
@@ -29,64 +29,64 @@
 
 UndoState::UndoState(const QString& name, const QString& description, QPixmap* pixmap) :
 	transactionCode(0),
-	actionName_(name),
-	actionDescription_(description),
-	actionPixmap_(pixmap),
-	undoObject_(nullptr)
-{
-
-}
-
-QString UndoState::getName()
-{
-	return actionName_;
+	m_actionName(name),
+	m_actionDescription(description),
+	m_actionPixmap(pixmap),
+	m_undoObject(nullptr)
+{
+
+}
+
+const QString& UndoState::getName() const
+{
+	return m_actionName;
 }
 
 void UndoState::setName(const QString &newName)
 {
-	actionName_ = newName;
-}
-
-QString UndoState::getDescription()
-{
-	return actionDescription_;
+	m_actionName = newName;
+}
+
+const QString& UndoState::getDescription() const
+{
+	return m_actionDescription;
 }
 
 void UndoState::setDescription(const QString &newDescription)
 {
-	actionDescription_ = newDescription;
+	m_actionDescription = newDescription;
 }
 
 QPixmap* UndoState::getPixmap()
 {
-	return actionPixmap_;
+	return m_actionPixmap;
 }
 
 void UndoState::setPixmap(QPixmap *pixmap)
 {
-	actionPixmap_ = pixmap;
+	m_actionPixmap = pixmap;
 }
 
 void UndoState::undo()
 {
-	if (undoObject_) // if !undoObject_ there's an error, hmmm
-		undoObject_->restore(this, true);
+	if (m_undoObject) // if !m_undoObject there's an error, hmmm
+		m_undoObject->restore(this, true);
 }
 
 void UndoState::redo()
 {
-	if (undoObject_)
-		undoObject_->restore(this, false);
+	if (m_undoObject)
+		m_undoObject->restore(this, false);
 }
 
 void UndoState::setUndoObject(UndoObject *object)
 {
-	undoObject_ = object->undoObjectPtr();
+	m_undoObject = object->undoObjectPtr();
 }
 
 UndoObject* UndoState::undoObject()
 {
-	return undoObject_;
+	return m_undoObject;
 }
 
 UndoState::~UndoState()
@@ -207,28 +207,28 @@
 
 TransactionState::TransactionState() : UndoState("")
 {
-	size_ = 0;
+	m_size = 0;
 }
 
 UndoState* TransactionState::at(int index) const
 {
 	if (index >= 0 && static_cast<uint>(index) < sizet())
-		return states_[index];
+		return m_states[index];
 	return nullptr;
 }
 
 UndoState* TransactionState::last() const
 {
-	if (!states_.empty())
-		return states_.at(size_ - 1);
+	if (!m_states.empty())
+		return m_states.at(m_size - 1);
 	return nullptr;
 }
 
 bool TransactionState::contains(int uid) const
 {
-	for (int i = 0; i < states_.size(); ++i)
-	{
-		UndoObject* undoObject = states_[i]->undoObject();
+	for (size_t i = 0; i < m_states.size(); ++i)
+	{
+		UndoObject* undoObject = m_states[i]->undoObject();
 		if (undoObject && undoObject->getUId() == static_cast<uint>(uid))
 			return true;
 	}
@@ -237,9 +237,9 @@
 
 bool TransactionState::containsOnly(int uid) const
 {
-	for (int i = 0; i < states_.size(); ++i)
-	{
-		UndoObject* undoObject = states_[i]->undoObject();
+	for (size_t i = 0; i < m_states.size(); ++i)
+	{
+		UndoObject* undoObject = m_states[i]->undoObject();
 		if (undoObject && undoObject->getUId() != static_cast<uint>(uid))
 			return false;
 	}
@@ -251,34 +251,34 @@
 	if (target && state)
 	{
 		state->setUndoObject(target);
-		states_.push_back(state);
-		++size_;
+		m_states.push_back(state);
+		++m_size;
 	}
 }
 
 uint TransactionState::sizet() const
 {
-	return size_;
+	return m_size;
 }
 
 void TransactionState::useActionName()
 {
-	if (size_ > 0)
-		setName(states_[size_ - 1]->getName());
+	if (m_size > 0)
+		setName(m_states[m_size - 1]->getName());
 }
 
 UndoObject* TransactionState::replace(ulong uid, UndoObject *newUndoObject)
 {
 	UndoObject *tmp = nullptr;
-	for (int i = 0; i < states_.size(); ++i)
-	{
-		TransactionState *ts = dynamic_cast<TransactionState*>(states_[i]);
+	for (size_t i = 0; i < m_states.size(); ++i)
+	{
+		TransactionState *ts = dynamic_cast<TransactionState*>(m_states[i]);
 		if (ts) // are we having a transaction_inside a transaction
 			ts->replace(uid, newUndoObject);
-		else if (states_[i]->undoObject() && states_[i]->undoObject()->getUId() == uid)
+		else if (m_states[i]->undoObject() && m_states[i]->undoObject()->getUId() == uid)
 		{
-			tmp = states_[i]->undoObject();
-			states_[i]->setUndoObject(newUndoObject);
+			tmp = m_states[i]->undoObject();
+			m_states[i]->setUndoObject(newUndoObject);
 		}
 	}
 	return tmp;
@@ -328,12 +328,12 @@
 
 TransactionState::~TransactionState()
 {
-	for (int i = 0; i < states_.size(); ++i)
-	{
-		if (states_[i])
+	for (size_t i = 0; i < m_states.size(); ++i)
+	{
+		if (m_states[i])
 		{
-			delete states_[i];
-			states_[i] = nullptr;
+			delete m_states[i];
+			m_states[i] = nullptr;
 		}
 	}
 }

Modified: trunk/Scribus/scribus/undostate.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22694&path=/trunk/Scribus/scribus/undostate.h
==============================================================================
--- trunk/Scribus/scribus/undostate.h	(original)
+++ trunk/Scribus/scribus/undostate.h	Sun Sep 16 11:50:19 2018
@@ -74,7 +74,7 @@
 	 * @brief Returns name of the state (action).
 	 * @return name of the state
 	 */
-	virtual QString getName();
+	virtual const QString& getName() const;
 
 	/**
 	 * @brief Set the name for this UndoState.
@@ -86,7 +86,7 @@
 	 * @brief Returns description of the state.
 	 * @return description of the state
 	 */
-	virtual QString getDescription();
+	virtual const QString& getDescription() const;
 
 	/**
 	 * @brief Set the description for this UndoState
@@ -122,13 +122,13 @@
 
 private:
 	/** @brief Name of the state (operation) (f.e. Move object) */
-	QString actionName_;
+	QString m_actionName;
 	/** @brief Detailed description of the state (operation). */
-	QString actionDescription_;
+	QString m_actionDescription;
 	/** @brief Icon related to the state (operation) */
-	QPixmap *actionPixmap_;
+	QPixmap *m_actionPixmap;
 	/** @brief UndoObject this state belongs to */
-	UndoObjectPtr undoObject_;
+	UndoObjectPtr m_undoObject;
 };
 
 /*** SimpleState **************************************************************************/
@@ -301,8 +301,10 @@
 	ScItemState(const QString& name, const QString& description = 0, QPixmap* pixmap = 0)
 	: SimpleState(name, description, pixmap) {}
 	~ScItemState() {}
+
 	void setItem(const C &c) { item_ = c; }
 	C getItem() const { return item_; }
+
 private:
 	C item_;
 };
@@ -315,9 +317,11 @@
 	ScItemsState(const QString& name, const QString& description = 0, QPixmap* pixmap = 0)
 	: SimpleState(name, description, pixmap) {}
 	~ScItemsState() {}
+
 	void insertItem(QString itemname, void * item) { pointerMap.insert(itemname, item); }
 	void* getItem(QString itemname) const { if (pointerMap.contains(itemname)) return pointerMap.value(itemname, NULL); else return NULL;}
 	QList< QPair<void*, int> > insertItemPos;
+
 private:
 	QMap<QString,void*> pointerMap;
 };
@@ -397,11 +401,12 @@
 	void undo();
 	/** @brief redo all UndoStates in this transaction */
 	void redo();
+
 private:
 	/** @brief Number of undo states stored in this transaction */
-	uint size_;
+	uint m_size;
 	/** @brief vector to keep the states in */
-	std::vector<UndoState*> states_;
+	std::vector<UndoState*> m_states;
 };
 
 #endif




More information about the scribus-commit mailing list