diff --git a/scribus/util.h b/scribus/util.h
index 6e4529fd4..f36de9d7b 100644
--- a/scribus/util.h
+++ b/scribus/util.h
@@ -154,6 +154,45 @@ void    SCRIBUS_API getDashArray(int dashtype, double linewidth, QVector<float>
 bool SCRIBUS_API convertOldTable(ScribusDoc *m_Doc, PageItem* gItem, QList<PageItem*> &gpL, QStack< QList<PageItem*> > *groupStackT = nullptr, QList<PageItem *> *target = nullptr);
 
 void SCRIBUS_API setWidgetBoldFont(QWidget* w, bool wantBold);
+/*!
+ *\brief
+ * check if name exists in list
+ * if it exists then return "name (#)", where # counts up from
+ * existing "name (#)"s (starting from 2)
+ * \retval the current name or a new unique name
+*/
+template<class STRINGLIST>
+QString getUniqueName(const QString& name, const STRINGLIST& list)
+{
+	if (!list.contains(name))
+		return name;
+
+	QString newName(name);
+
+	QString prefix(newName);
+	int suffixNum = 1;
+
+	// capture the name and the index, if any
+	// fred (5)
+	// ^^^^  ^   (where ^ means captured)
+	static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
+	if (rx.indexIn(newName) != -1)
+	{
+		QStringList matches = rx.capturedTexts();
+		prefix = matches[1];
+		suffixNum = matches[2].toInt();
+	}
+
+	do
+	{
+		suffixNum++;
+		newName = prefix + " (" + QString::number(suffixNum) + ")";
+	}
+	while (list.contains(newName));
+
+	return newName;
+}
+
 /*!
  *\brief
  * check if name exists in list
