View Issue Details

IDProjectCategoryView StatusLast Update
0015947ScribusGeneralpublic2019-11-14 10:04
Reporterale Assigned Toale  
PrioritynormalSeverityminorReproducibilityN/A
Status assignedResolutionopen 
Product Version1.5.6.svn 
Summary0015947: [PATCH] refactor the master pages import: .ui, file open dialog, separate from page import
Description- create an ui file,
- file open is triggered before the dialog,
- separate page / master page import

here is the merge request with link to the appimage:

https://gitlab.com/scribus/scribus/merge_requests/15

as soon as this patch is accepted, i would do the same for the page import and remove mergedoc.h|cpp
TagsNo tags attached.
PatchYes

Activities

ale

2019-11-14 09:39

manager  

masterpages-fileopen.diff (9,344 bytes)   
diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt
index 3a6e69b38..efcdec0b2 100644
--- a/scribus/CMakeLists.txt
+++ b/scribus/CMakeLists.txt
@@ -128,6 +128,7 @@ set(SCRIBUS_UI_SRC
 	ui/pageitemattributes.ui
 	ui/pagepalette_pagesbase.ui
 	ui/pagepalette_masterpagesbase.ui
+	ui/pagepalette_masterpages_selectbase.ui
 	ui/picsearch.ui
 	ui/picsearchoptions.ui
 	ui/picstatus.ui
@@ -415,6 +416,7 @@ set(SCRIBUS_MOC_CLASSES
 	ui/pagepalette.h
 	ui/pagepalette_pages.h
 	ui/pagepalette_masterpages.h
+	ui/pagepalette_masterpages_select.h
 	ui/pagepalette_widgets.h
 	ui/pagepropertiesdialog.h
 	ui/pageselector.h
@@ -916,6 +918,7 @@ set(SCRIBUS_SOURCES
 	ui/pagepalette.cpp
 	ui/pagepalette_pages.cpp
 	ui/pagepalette_masterpages.cpp
+	ui/pagepalette_masterpages_select.cpp
 	ui/pagepalette_widgets.cpp
 	ui/pagepropertiesdialog.cpp
 	ui/pageselector.cpp
diff --git a/scribus/ui/pagepalette_masterpages.cpp b/scribus/ui/pagepalette_masterpages.cpp
index 8490292a4..bf06d460e 100644
--- a/scribus/ui/pagepalette_masterpages.cpp
+++ b/scribus/ui/pagepalette_masterpages.cpp
@@ -26,9 +26,10 @@ for which a new license (GPL+exception) is in place.
 #include "canvasmode.h"
 #include "commonstrings.h"
 #include "iconmanager.h"
-#include "mergedoc.h"
+#include "pagepalette_masterpages_select.h"
 #include "newtemp.h"
 #include "pagestructs.h"
+#include "prefsfile.h"
 #include "prefsmanager.h"
 #include "scpage.h"
 #include "scribus.h"
@@ -346,8 +347,19 @@ void PagePalette_MasterPages::newMasterPage()
 
 void PagePalette_MasterPages::importPage()
 {
-	QScopedPointer<MergeDoc> dia(new MergeDoc(this, true));
-	if (!dia->exec())
+	auto dirs = PrefsManager::instance().prefsFile->getContext("dirs")->get("merge", ".");
+	CustomFDialog openDialog(this, dirs, tr("Select the Document with the Master Pages"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)"));
+
+	if (openDialog.exec() != QDialog::Accepted)
+		return;
+
+	auto filename = openDialog.selectedFile();
+
+	if (filename.isEmpty())
+		return;
+
+	PagePalette_Masterpages_Select dia(this, filename);
+	if (!dia.exec())
 		return;
 
 	if (m_doc->appMode == modeEditClip)
@@ -356,9 +368,9 @@ void PagePalette_MasterPages::importPage()
 	qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
 	int nr = m_doc->Pages->count();
 
-	auto indexes = dia->getMasterPageIndexes();
+	auto indexes = dia.getMasterPageIndexes();
 	QString lastName;
-	for (auto name: dia->getMasterPageNames())
+	for (auto name: dia.getMasterPageNames())
 	{
 		name = getUniqueName(name, m_doc->MasterNames);
 		m_doc->setCurrentPage(m_doc->addMasterPage(nr, name));
@@ -368,7 +380,7 @@ void PagePalette_MasterPages::importPage()
 
 		//CB TODO: If we are loading to a new name, we rely on doc->onpage in
 		//FileLoader::PasteItem as this call doesn't pass in the new destination page
-		m_doc->scMW()->loadPage(dia->getFromDoc(), indexes.first(), true, name);
+		m_doc->scMW()->loadPage(filename, indexes.first(), true, name);
 		qApp->processEvents();
 
 		indexes.removeFirst();
diff --git a/scribus/ui/pagepalette_masterpages_select.cpp b/scribus/ui/pagepalette_masterpages_select.cpp
new file mode 100644
index 000000000..d2806f23f
--- /dev/null
+++ b/scribus/ui/pagepalette_masterpages_select.cpp
@@ -0,0 +1,56 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#include "pagepalette_masterpages_select.h"
+
+#include "fileloader.h"
+#include "iconmanager.h"
+
+PagePalette_Masterpages_Select::PagePalette_Masterpages_Select(QWidget* parent, QString filename) :
+	QDialog(parent)
+{
+	setupUi(this);
+
+	setWindowTitle(tr("Import Master Pages"));
+	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
+
+	fromLabel->setText(tr("From Document:") );
+	fromValueLabel->setText(filename);
+	importLabel->setText(tr("&Import Master Page(s):"));
+	read(filename);
+
+	connect(importButton, &QPushButton::clicked, this, &PagePalette_Masterpages_Select::accept);
+	connect(cancelButton, &QPushButton::clicked, this, &PagePalette_Masterpages_Select::reject);
+}
+
+void PagePalette_Masterpages_Select::read(QString filename)
+{
+	qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
+	FileLoader fileLoader(filename);
+	if (fileLoader.testFile() == -1)
+		return;
+	int dummy1 = 0, dummy2 = 0;
+	QStringList masterPageNames;
+	if (fileLoader.readPageCount(&dummy1, &dummy2, masterPageNames))
+		masterPagesList->addItems(masterPageNames);
+	qApp->restoreOverrideCursor();
+}
+
+const QStringList PagePalette_Masterpages_Select::getMasterPageNames() const
+{
+	QStringList result;
+	for (const auto item : masterPagesList->selectedItems())
+		result << item->text();
+	return result;
+}
+
+QList<int> PagePalette_Masterpages_Select::getMasterPageIndexes() const
+{
+	QList<int> result;
+	for (const auto& row: masterPagesList->selectionModel()->selectedRows())
+		result << row.row();
+	return result;
+}
diff --git a/scribus/ui/pagepalette_masterpages_select.h b/scribus/ui/pagepalette_masterpages_select.h
new file mode 100644
index 000000000..222140799
--- /dev/null
+++ b/scribus/ui/pagepalette_masterpages_select.h
@@ -0,0 +1,33 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/**
+ * "import master pages" dialog for the "master pages" window.
+ */
+
+#ifndef PAGEPALETTE_MASTERPAGES_SELECT_H
+#define PAGEPALETTE_MASTERPAGES_SELECT_H
+
+#include "ui_pagepalette_masterpages_selectbase.h"
+
+#include <QDialog>
+
+#include "scribusapi.h"
+
+class SCRIBUS_API PagePalette_Masterpages_Select : public QDialog, Ui::PagePalette_Masterpages_Select_Base
+{
+	Q_OBJECT
+public:
+	PagePalette_Masterpages_Select(QWidget* parent, QString filename);
+	~PagePalette_Masterpages_Select() = default;
+
+	const QStringList getMasterPageNames() const;
+	QList<int> getMasterPageIndexes() const;
+private:
+	void read(QString filename);
+};
+
+#endif // PAGEPALETTE_MASTERPAGES_SELECT_H
diff --git a/scribus/ui/pagepalette_masterpages_selectbase.ui b/scribus/ui/pagepalette_masterpages_selectbase.ui
new file mode 100644
index 000000000..4ebd2db68
--- /dev/null
+++ b/scribus/ui/pagepalette_masterpages_selectbase.ui
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PagePalette_Masterpages_Select_Base</class>
+ <widget class="QDialog" name="PagePalette_Masterpages_Select_Base">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Import Master Pages</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QLabel" name="fromLabel">
+       <property name="text">
+        <string>From Document:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="fromValueLabel">
+       <property name="text">
+        <string>...</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QLabel" name="importLabel">
+     <property name="text">
+      <string>&amp;Import Master Page(s):</string>
+     </property>
+     <property name="buddy">
+      <cstring>masterPagesList</cstring>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QListWidget" name="masterPagesList">
+     <property name="selectionMode">
+      <enum>QAbstractItemView::ExtendedSelection</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="importButton">
+       <property name="text">
+        <string>&amp;Import</string>
+       </property>
+       <property name="default">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="cancelButton">
+       <property name="text">
+        <string>&amp;Cancel</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
masterpages-fileopen.diff (9,344 bytes)   

Issue History

Date Modified Username Field Change
2019-11-14 09:39 ale New Issue
2019-11-14 09:39 ale File Added: masterpages-fileopen.diff
2019-11-14 10:04 ale Assigned To => ale
2019-11-14 10:04 ale Status new => assigned