r24161 by craig - Code cleanup

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 3 15:51:30 UTC 2020


Author: craig
Date: Tue Nov  3 15:51:30 2020
New Revision: 24161

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24161
Log:
Code cleanup

Modified:
    trunk/Scribus/scribus/ui/layers.cpp
    trunk/Scribus/scribus/ui/pageselector.cpp
    trunk/Scribus/scribus/ui/pageselector.h
    trunk/Scribus/scribus/ui/picstatus.h
    trunk/Scribus/scribus/util.cpp

Modified: trunk/Scribus/scribus/ui/layers.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24161&path=/trunk/Scribus/scribus/ui/layers.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/layers.cpp	(original)
+++ trunk/Scribus/scribus/ui/layers.cpp	Tue Nov  3 15:51:30 2020
@@ -25,6 +25,7 @@
 #include <QMessageBox>
 #include <QPixmap>
 #include <QPushButton>
+#include <QSignalBlocker>
 #include <QSpacerItem>
 #include <QTableWidget>
 #include <QTableWidgetItem>
@@ -699,8 +700,7 @@
 	textLabel1->setText( tr( "Blend Mode:" ) );
 
 	int  oldBlendMode = blendMode->currentIndex();
-	bool blendModeBlocked = blendMode->blockSignals(true);
-
+	QSignalBlocker signalBlocker(blendMode);
 	blendMode->clear();
 	blendMode->addItem( tr("Normal"));
 	blendMode->addItem( tr("Darken"));
@@ -720,7 +720,6 @@
 	blendMode->addItem( tr("Luminosity"));
 
 	blendMode->setCurrentIndex(oldBlendMode);
-	blendMode->blockSignals(blendModeBlocked);
 
 	textLabel2->setText( tr( "Opacity:" ) );
 	opacitySpinBox->setSuffix( tr(" %"));

Modified: trunk/Scribus/scribus/ui/pageselector.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24161&path=/trunk/Scribus/scribus/ui/pageselector.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/pageselector.cpp	(original)
+++ trunk/Scribus/scribus/ui/pageselector.cpp	Tue Nov  3 15:51:30 2020
@@ -16,6 +16,7 @@
 #include <QPixmap>
 #include <QPushButton>
 #include <QRegExp>
+#include <QSignalBlocker>
 #include <QToolTip>
 #include <QValidator>
 
@@ -24,11 +25,10 @@
 #include "iconmanager.h"
 #include "util.h"
 
-PageSelector::PageSelector( QWidget* parent, int maxPg ) : QWidget( parent, nullptr )
-{
-	pageCountString = "%1" ;
-	m_lastPage = maxPg;
-	m_currentPage = 1;
+PageSelector::PageSelector( QWidget* parent, int maximumPage ) : QWidget( parent, Qt::WindowFlags() )
+{
+	pageCountString = "%1";
+	m_lastPage = maximumPage;
 	pageSelectorLayout = new QHBoxLayout( this );
 	pageSelectorLayout->setMargin(0);
 	pageSelectorLayout->setSpacing(1);
@@ -86,6 +86,126 @@
 		lastButton->setEnabled(false);
 	}
 
+	iconSetChange();
+
+	pageSelectorLayout->addWidget( startButton );
+	pageSelectorLayout->addWidget( backButton );
+	pageSelectorLayout->addWidget( m_pageCombo );
+	pageSelectorLayout->addWidget( pageCountLabel );
+	pageSelectorLayout->addWidget( forwardButton );
+	pageSelectorLayout->addWidget( lastButton );
+
+	languageChange();
+
+	// signals and slots connections
+	connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
+
+	connect( m_pageCombo, SIGNAL( activated(int) ), this, SLOT( gotoPage(int) ) );
+	connect( backButton, SIGNAL( clicked() ), this, SLOT( goBackward()) );
+	connect( startButton, SIGNAL( clicked() ), this, SLOT( goToStart() ) );
+	connect( forwardButton, SIGNAL( clicked() ), this, SLOT( goForward() ) );
+	connect( lastButton, SIGNAL( clicked() ), this, SLOT( goToEnd() ) );
+}
+
+bool PageSelector::hasFocus()
+{
+	return m_pageCombo->hasFocus();
+}
+
+void PageSelector::clearFocus()
+{
+	m_pageCombo->clearFocus();
+}
+
+void PageSelector::focusPolicy(Qt::FocusPolicy policy)
+{
+	m_pageCombo->setFocusPolicy(policy);
+}
+
+void PageSelector::setFont(const QFont& font)
+{
+	pageCountLabel->setFont(font);
+	QWidget::setFont(font);
+}
+
+int PageSelector::getCurrentPage()
+{
+	return m_currentPage;
+}
+
+void PageSelector::gotoPage(int i)
+{
+	clearFocus();
+	setGUIForPage(i);
+	emit pageChanged(i + 1);
+}
+
+void PageSelector::setGUIForPage(int i)
+{
+	QSignalBlocker signalBlocker(m_pageCombo);
+	m_pageCombo->setCurrentIndex(i);
+	m_currentPage = i + 1;
+	setCurrentComboItem(m_pageCombo, QString::number(m_currentPage));
+	backButton->setEnabled(i != 0);
+	startButton->setEnabled(i != 0);
+	forwardButton->setEnabled(i != m_lastPage - 1);
+	lastButton->setEnabled(i != m_lastPage - 1);
+}
+
+void PageSelector::setMaximum(int i)
+{
+	QSignalBlocker signalBlocker(m_pageCombo);
+	m_pageCombo->clear();
+	m_lastPage = i;
+	m_validator->setRange(1, m_lastPage);
+	for (int b = 0; b < m_lastPage; ++b)
+	{
+		m_pageCombo->addItem(QString::number(b + 1));
+	}
+	setCurrentComboItem(m_pageCombo, QString::number(m_currentPage));
+	pageCountLabel->setText(pageCountString.arg(m_lastPage));
+}
+
+void PageSelector::goToStart()
+{
+	if (m_currentPage == 1)
+		return;
+	gotoPage(0);
+}
+
+void PageSelector::goToEnd()
+{
+	if (m_currentPage == m_lastPage)
+		return;
+	gotoPage(m_lastPage - 1);
+}
+
+void PageSelector::goBackward()
+{
+	m_currentPage--;
+	if (m_currentPage < 1)
+		m_currentPage = 1;
+	gotoPage(m_currentPage - 1);
+}
+
+void PageSelector::goForward()
+{
+	m_currentPage++;
+	if (m_currentPage > m_lastPage)
+		m_currentPage = m_lastPage;
+	gotoPage(m_currentPage - 1);
+}
+
+void PageSelector::changeEvent(QEvent *e)
+{
+	if (e->type() == QEvent::LanguageChange)
+		languageChange();
+	else
+		QWidget::changeEvent(e);
+}
+
+void PageSelector::iconSetChange()
+{
 	QByteArray stylesheet;
 	if (loadRawText(ScPaths::instance().libDir() + "scribus.css", stylesheet))
 	{
@@ -95,136 +215,6 @@
 		stylesheet.replace("___downArrow___", da);
 		setStyleSheet(QString(stylesheet));
 	}
-
-	pageSelectorLayout->addWidget( startButton );
-	pageSelectorLayout->addWidget( backButton );
-	pageSelectorLayout->addWidget( m_pageCombo );
-	pageSelectorLayout->addWidget( pageCountLabel );
-	pageSelectorLayout->addWidget( forwardButton );
-	pageSelectorLayout->addWidget( lastButton );
-
-	languageChange();
-
-	// signals and slots connections
-	connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
-
-	connect( m_pageCombo, SIGNAL( activated(int) ), this, SLOT( gotoPage(int) ) );
-	connect( backButton, SIGNAL( clicked() ), this, SLOT( goBackward()) );
-	connect( startButton, SIGNAL( clicked() ), this, SLOT( goToStart() ) );
-	connect( forwardButton, SIGNAL( clicked() ), this, SLOT( goForward() ) );
-	connect( lastButton, SIGNAL( clicked() ), this, SLOT( goToEnd() ) );
-}
-
-bool PageSelector::hasFocus()
-{
-	return m_pageCombo->hasFocus();
-}
-
-void PageSelector::clearFocus()
-{
-	m_pageCombo->clearFocus();
-}
-
-void PageSelector::focusPolicy(Qt::FocusPolicy policy)
-{
-	m_pageCombo->setFocusPolicy(policy);
-}
-
-void PageSelector::setFont(const QFont &fo)
-{
-	pageCountLabel->setFont(fo);
-	QWidget::setFont(fo);
-}
-
-int PageSelector::getCurrentPage()
-{
-	return m_currentPage;
-}
-
-void PageSelector::gotoPage(int i)
-{
-	clearFocus();
-	setGUIForPage(i);
-	emit pageChanged(i + 1);
-}
-
-void PageSelector::setGUIForPage(int i)
-{
-	bool sigBlocked = m_pageCombo->blockSignals(true);
-	m_pageCombo->setCurrentIndex(i);
-	setCurrentComboItem(m_pageCombo, QString::number(i + 1));
-	m_currentPage = i + 1;
-	backButton->setEnabled(i != 0);
-	startButton->setEnabled(i != 0);
-	forwardButton->setEnabled(i != m_lastPage - 1);
-	lastButton->setEnabled(i != m_lastPage - 1);
-	m_pageCombo->blockSignals(sigBlocked);
-}
-
-void PageSelector::setMaximum(int i)
-{
-	bool sigBlocked = m_pageCombo->blockSignals(true);
-	m_pageCombo->clear();
-	m_lastPage = i;
-	m_validator->setRange(1, m_lastPage);
-	for (int b = 0; b < m_lastPage; ++b)
-	{
-		m_pageCombo->addItem(QString::number(b + 1));
-	}
-	setCurrentComboItem(m_pageCombo, QString::number(m_currentPage));
-	pageCountLabel->setText(pageCountString.arg(m_lastPage));
-	m_pageCombo->blockSignals(sigBlocked);
-}
-
-void PageSelector::goToStart()
-{
-	if (m_currentPage == 1)
-		return;
-	gotoPage(0);
-}
-
-void PageSelector::goToEnd()
-{
-	if (m_currentPage == m_lastPage)
-		return;
-	gotoPage(m_lastPage - 1);
-}
-
-void PageSelector::goBackward()
-{
-	m_currentPage--;
-	if (m_currentPage < 1)
-		m_currentPage = 1;
-	gotoPage(m_currentPage - 1);
-}
-
-void PageSelector::goForward()
-{
-	m_currentPage++;
-	if (m_currentPage > m_lastPage)
-		m_currentPage = m_lastPage;
-	gotoPage(m_currentPage - 1);
-}
-
-void PageSelector::changeEvent(QEvent *e)
-{
-	if (e->type() == QEvent::LanguageChange)
-		languageChange();
-	else
-		QWidget::changeEvent(e);
-}
-
-void PageSelector::iconSetChange()
-{
-	QByteArray stylesheet;
-	if (loadRawText(ScPaths::instance().libDir() + "scribus.css", stylesheet))
-	{
-		QString downArrow(IconManager::instance().pathForIcon("16/go-down.png"));
-		QByteArray da;
-		da.append(downArrow.toUtf8());
-		stylesheet.replace("___downArrow___", da);
-		setStyleSheet(QString(stylesheet));
-	}
 }
 
 void PageSelector::languageChange()

Modified: trunk/Scribus/scribus/ui/pageselector.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24161&path=/trunk/Scribus/scribus/ui/pageselector.h
==============================================================================
--- trunk/Scribus/scribus/ui/pageselector.h	(original)
+++ trunk/Scribus/scribus/ui/pageselector.h	Tue Nov  3 15:51:30 2020
@@ -26,12 +26,12 @@
 	Q_OBJECT
 
 public:
-	PageSelector( QWidget* parent, int maxPg = 0 );
+	PageSelector(QWidget* parent, int maximumPage = 0 );
 	~PageSelector() {};
 	
 	bool hasFocus();
 	void focusPolicy(Qt::FocusPolicy policy);
-	void setFont ( const QFont & );
+	void setFont(const QFont& font);
 	int getCurrentPage();
 
 public slots:

Modified: trunk/Scribus/scribus/ui/picstatus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24161&path=/trunk/Scribus/scribus/ui/picstatus.h
==============================================================================
--- trunk/Scribus/scribus/ui/picstatus.h	(original)
+++ trunk/Scribus/scribus/ui/picstatus.h	Tue Nov  3 15:51:30 2020
@@ -21,7 +21,7 @@
 public:
 	PicItem(QListWidget* parent, const QString& text, const QPixmap& pix, PageItem* pgItem);
 	~PicItem() {};
-	PageItem *PageItemObject;
+	PageItem *PageItemObject {nullptr};
 };
 
 
@@ -106,9 +106,9 @@
 	bool loadPict(PageItem* item, const QString & newFilePath);
 
 private:
-	ScribusDoc *m_Doc;
-	PageItem *currItem;
-	int sortOrder;
+	ScribusDoc *m_Doc {nullptr};
+	PageItem *currItem {nullptr};
+	int sortOrder {0};
 
 };
 #endif

Modified: trunk/Scribus/scribus/util.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24161&path=/trunk/Scribus/scribus/util.cpp
==============================================================================
--- trunk/Scribus/scribus/util.cpp	(original)
+++ trunk/Scribus/scribus/util.cpp	Tue Nov  3 15:51:30 2020
@@ -30,6 +30,7 @@
 #include <QDomElement>
 #include <QMessageBox>
 #include <QProcess>
+#include <QSignalBlocker>
 
 #include "pageitem.h"
 #include "pageitem_table.h"
@@ -792,29 +793,26 @@
 
 void setCurrentComboItem(QComboBox *box, const QString& text)
 {
-	bool sigBlocked = box->blockSignals(true);
+	QSignalBlocker signalBlocker(box);
 	int ind = box->findText(text);
 	if (ind > -1)
 		box->setCurrentIndex(ind);
-	box->blockSignals(sigBlocked);
 }
 
 void setCurrentComboItemFromData(QComboBox *box, const QString& data)
 {
-	bool sigBlocked = box->blockSignals(true);
+	QSignalBlocker signalBlocker(box);
 	int ind = box->findData(data);
 	if (ind > -1)
 		box->setCurrentIndex(ind);
-	box->blockSignals(sigBlocked);
 }
 
 void removeComboItem(QComboBox *box, const QString& text)
 {
-	bool sigBlocked = box->blockSignals(true);
+	QSignalBlocker signalBlocker(box);
 	int ind = box->findText(text);
 	if (ind > -1)
 		box->removeItem(ind);
-	box->blockSignals(sigBlocked);
 }
 
 QString readAdobeUniCodeString(QDataStream &s)




More information about the scribus-commit mailing list