- refactored stuff

Sun, 29 Jun 2014 15:22:43 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 29 Jun 2014 15:22:43 +0300
changeset 814
c8ef30fd0e54
parent 813
987f35e96467
child 815
efe34366e56a

- refactored stuff

src/basics.cc file | annotate | diff | comparison | revisions
src/colors.h file | annotate | diff | comparison | revisions
src/configDialog.cc file | annotate | diff | comparison | revisions
src/partDownloader.cc file | annotate | diff | comparison | revisions
src/partDownloader.h file | annotate | diff | comparison | revisions
--- a/src/basics.cc	Sun Jun 22 21:13:50 2014 +0300
+++ b/src/basics.cc	Sun Jun 29 15:22:43 2014 +0300
@@ -120,10 +120,10 @@
 
 // =============================================================================
 //
-Matrix::Matrix (const std::initializer_list< double >& vals)
+Matrix::Matrix (const std::initializer_list<double>& vals)
 {
 	assert (vals.size() == 9);
-	memcpy (&m_vals[0], & (*vals.begin()), sizeof m_vals);
+	memcpy (&m_vals[0], vals.begin(), sizeof m_vals);
 }
 
 // =============================================================================
@@ -133,7 +133,7 @@
 	for (int i = 0; i < 3; ++i)
 	{
 		for (int j = 0; j < 3; ++j)
-			print ("%1\t", m_vals[ (i * 3) + j]);
+			print ("%1\t", m_vals[i * 3 + j]);
 
 		print ("\n");
 	}
@@ -203,8 +203,10 @@
 bool Matrix::operator== (const Matrix& other) const
 {
 	for (int i = 0; i < 9; ++i)
+	{
 		if (value (i) != other[i])
 			return false;
+	}
 
 	return true;
 }
@@ -222,7 +224,7 @@
 {
 	reset();
 
-	if (not getCurrentDocument())
+	if (getCurrentDocument() == null)
 		return;
 
 	for (LDObjectPtr obj : getCurrentDocument()->objects())
--- a/src/colors.h	Sun Jun 22 21:13:50 2014 +0300
+++ b/src/colors.h	Sun Jun 29 15:22:43 2014 +0300
@@ -43,23 +43,15 @@
 
 class LDColor;
 
-class LDColorData
+struct LDColorData
 {
-protected:
 	QString _name;
 	QString _hexcode;
 	QColor _faceColor;
 	QColor _edgeColor;
 	qint32 _index;
-	friend class LDConfigParser;
-	friend class LDColor;
-	friend void initColors();
-
-public:
-	LDColorData(){}
 };
 
-
 class LDColor : public QSharedPointer<LDColorData>
 {
 	SHARED_POINTER_DERIVATIVE (LDColor)
--- a/src/configDialog.cc	Sun Jun 22 21:13:50 2014 +0300
+++ b/src/configDialog.cc	Sun Jun 29 15:22:43 2014 +0300
@@ -82,13 +82,39 @@
 
 const char* g_extProgPathFilter =
 #ifdef _WIN32
-	"Applications (*.exe)(*.exe);;All files (*.*)(*.*)";
-#else
-	"";
+	"Applications (*.exe)(*.exe);;"
 #endif
+	"All files (*.*)(*.*)";
 
-// =============================================================================
-// =============================================================================
+//
+//
+static struct LDExtProgInfo
+{
+	QString const	name;
+	QString const	iconname;
+	QString* const	path;
+	QLineEdit*		input;
+	QPushButton*	setPathButton;
+	bool* const		wine;
+	QCheckBox*		wineBox;
+} g_LDExtProgInfo[] =
+{
+#ifndef _WIN32
+# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null, &cfg::LOWNAME##UsesWine, null },
+#else
+# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null, null, null },
+#endif
+	EXTPROG (Ytruder, ytruder)
+	EXTPROG (Rectifier, rectifier)
+	EXTPROG (Intersector, intersector)
+	EXTPROG (Isecalc, isecalc)
+	EXTPROG (Coverer, coverer)
+	EXTPROG (Edger2, edger2)
+#undef EXTPROG
+};
+
+//
+//
 ConfigDialog::ConfigDialog (ConfigDialog::Tab deftab, QWidget* parent, Qt::WindowFlags f) :
 	QDialog (parent, f)
 {
@@ -174,24 +200,24 @@
 		this, SLOT (selectPage (int)));
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 ConfigDialog::~ConfigDialog()
 {
 	delete ui;
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void ConfigDialog::selectPage (int row)
 {
 	ui->m_pagelist->setCurrentRow (row);
 	ui->m_pages->setCurrentIndex (row);
 }
 
-// =============================================================================
+//
 // Adds a shortcut entry to the list of shortcuts.
-// =============================================================================
+//
 void ConfigDialog::addShortcut (QAction* act)
 {
 	ShortcutListItem* item = new ShortcutListItem;
@@ -208,38 +234,9 @@
 	ui->shortcutsList->insertItem (ui->shortcutsList->count(), item);
 }
 
-// =============================================================================
-// =============================================================================
-static struct LDExtProgInfo
-{
-	const QString	name,
-					iconname;
-	QString* const	path;
-	QLineEdit*		input;
-	QPushButton*	setPathButton;
-#ifndef _WIN32
-	bool* const		wine;
-	QCheckBox*		wineBox;
-#endif // _WIN32
-} g_LDExtProgInfo[] =
-{
-#ifndef _WIN32
-# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null, &cfg::LOWNAME##UsesWine, null },
-#else
-# define EXTPROG(NAME, LOWNAME) { #NAME, #LOWNAME, &cfg::LOWNAME##Path, null, null },
-#endif
-	EXTPROG (Ytruder, ytruder)
-	EXTPROG (Rectifier, rectifier)
-	EXTPROG (Intersector, intersector)
-	EXTPROG (Isecalc, isecalc)
-	EXTPROG (Coverer, coverer)
-	EXTPROG (Edger2, edger2)
-#undef EXTPROG
-};
-
-// =============================================================================
+//
 // Initializes the stuff in the ext programs tab
-// =============================================================================
+//
 void ConfigDialog::initExtProgs()
 {
 	QGridLayout* pathsLayout = new QGridLayout;
@@ -265,12 +262,13 @@
 		pathsLayout->addWidget (input, row, 2);
 		pathsLayout->addWidget (setPathButton, row, 3);
 
-#ifndef _WIN32
-		QCheckBox* wineBox = new QCheckBox ("Wine");
-		wineBox->setChecked (*info.wine);
-		info.wineBox = wineBox;
-		pathsLayout->addWidget (wineBox, row, 4);
-#endif
+		if (info.wine != null)
+		{
+			QCheckBox* wineBox = new QCheckBox ("Wine");
+			wineBox->setChecked (*info.wine);
+			info.wineBox = wineBox;
+			pathsLayout->addWidget (wineBox, row, 4);
+		}
 
 		++row;
 	}
@@ -278,9 +276,9 @@
 	ui->extProgs->setLayout (pathsLayout);
 }
 
-// =============================================================================
+//
 // Set the settings based on widget data.
-// =============================================================================
+//
 void ConfigDialog::applySettings()
 {
 	// Apply configuration
@@ -320,9 +318,8 @@
 	{
 		*info.path = info.input->text();
 
-#ifndef _WIN32
-		*info.wine = info.wineBox->isChecked();
-#endif // _WIN32
+		if (info.wine != null)
+			*info.wine = info.wineBox->isChecked();
 	}
 
 	// Apply shortcuts
@@ -340,9 +337,9 @@
 	g_win->updateDocumentList();
 }
 
-// =============================================================================
+//
 // A dialog button was clicked
-// =============================================================================
+//
 void ConfigDialog::buttonClicked (QAbstractButton* button)
 {
 	typedef QDialogButtonBox QDDB;
@@ -361,9 +358,9 @@
 	}
 }
 
-// =============================================================================
+//
 // Update the list of color toolbar items in the quick color tab.
-// =============================================================================
+//
 void ConfigDialog::updateQuickColorList (LDQuickColor* sel)
 {
 	for (QListWidgetItem * item : quickColorItems)
@@ -408,9 +405,9 @@
 	}
 }
 
-// =============================================================================
+//
 // Quick colors: add or edit button was clicked.
-// =============================================================================
+//
 void ConfigDialog::slot_setColor()
 {
 	LDQuickColor* entry = null;
@@ -453,9 +450,9 @@
 	updateQuickColorList (entry);
 }
 
-// =============================================================================
+//
 // Remove a quick color
-// =============================================================================
+//
 void ConfigDialog::slot_delColor()
 {
 	if (ui->quickColorList->selectedItems().isEmpty())
@@ -466,9 +463,9 @@
 	updateQuickColorList();
 }
 
-// =============================================================================
+//
 // Move a quick color up/down
-// =============================================================================
+//
 void ConfigDialog::slot_moveColor()
 {
 	const bool up = (static_cast<QPushButton*> (sender()) == ui->quickColor_moveUp);
@@ -490,7 +487,7 @@
 	updateQuickColorList (&quickColors[dest]);
 }
 
-// =============================================================================
+//
 //
 // Add a separator to quick colors
 //
@@ -500,7 +497,7 @@
 	updateQuickColorList (&quickColors[quickColors.size() - 1]);
 }
 
-// =============================================================================
+//
 //
 // Clear all quick colors
 //
@@ -510,7 +507,7 @@
 	updateQuickColorList();
 }
 
-// =============================================================================
+//
 //
 // Pick a color and set the appropriate configuration option.
 //
@@ -531,30 +528,30 @@
 	}
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void ConfigDialog::slot_setGLBackground()
 {
 	pickColor (cfg::backgroundColor, ui->backgroundColorButton);
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void ConfigDialog::slot_setGLForeground()
 {
 	pickColor (cfg::mainColor, ui->mainColorButton);
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void ConfigDialog::slot_setGLSelectColor()
 {
 	pickColor (cfg::selectColorBlend, ui->selColorButton);
 }
 
-// =============================================================================
+//
 // Sets background color of a given button.
-// =============================================================================
+//
 void ConfigDialog::setButtonBackground (QPushButton* button, QString value)
 {
 	button->setIcon (getIcon ("colorselect"));
@@ -562,9 +559,9 @@
 	button->setStyleSheet (format ("background-color: %1", value));
 }
 
-// =============================================================================
+//
 // Finds the given list widget item in the list of widget items given.
-// =============================================================================
+//
 int ConfigDialog::getItemRow (QListWidgetItem* item, QList<QListWidgetItem*>& haystack)
 {
 	int i = 0;
@@ -580,9 +577,9 @@
 	return -1;
 }
 
-// =============================================================================
+//
 // Which quick color is currently selected?
-// =============================================================================
+//
 QListWidgetItem* ConfigDialog::getSelectedQuickColor()
 {
 	if (ui->quickColorList->selectedItems().isEmpty())
@@ -591,9 +588,9 @@
 	return ui->quickColorList->selectedItems() [0];
 }
 
-// =============================================================================
+//
 // Get the list of shortcuts selected
-// =============================================================================
+//
 QList<ShortcutListItem*> ConfigDialog::getShortcutSelection()
 {
 	QList<ShortcutListItem*> out;
@@ -604,9 +601,9 @@
 	return out;
 }
 
-// =============================================================================
+//
 // Edit the shortcut of a given action.
-// =============================================================================
+//
 void ConfigDialog::slot_setShortcut()
 {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
@@ -620,9 +617,9 @@
 		setShortcutText (item);
 }
 
-// =============================================================================
+//
 // Reset a shortcut to defaults
-// =============================================================================
+//
 void ConfigDialog::slot_resetShortcut()
 {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
@@ -634,9 +631,9 @@
 	}
 }
 
-// =============================================================================
+//
 // Remove the shortcut of an action.
-// =============================================================================
+//
 void ConfigDialog::slot_clearShortcut()
 {
 	QList<ShortcutListItem*> sel = getShortcutSelection();
@@ -648,9 +645,9 @@
 	}
 }
 
-// =============================================================================
+//
 // Set the path of an external program
-// =============================================================================
+//
 void ConfigDialog::slot_setExtProgPath()
 {
 	const LDExtProgInfo* info = null;
@@ -673,7 +670,6 @@
 	info->input->setText (fpath);
 }
 
-// =============================================================================
 //
 // '...' button pressed for the download path
 //
@@ -683,7 +679,7 @@
 	ui->downloadPath->setText (dpath);
 }
 
-// =============================================================================
+//
 //
 // Updates the text string for a given shortcut list item
 //
@@ -695,9 +691,9 @@
 	item->setText (format ("%1 (%2)", label, keybind));
 }
 
-// =============================================================================
+//
 // Gets the configuration string of the quick color toolbar
-// =============================================================================
+//
 QString ConfigDialog::quickColorString()
 {
 	QString val;
@@ -716,13 +712,8 @@
 	return val;
 }
 
-// ===============================================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// ===============================================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// ===============================================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// ===============================================================================================
+//
+//
 KeySequenceDialog::KeySequenceDialog (QKeySequence seq, QWidget* parent, Qt::WindowFlags f) :
 	QDialog (parent, f), seq (seq)
 {
@@ -741,8 +732,8 @@
 	updateOutput();
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 bool KeySequenceDialog::staticDialog (ShortcutListItem* item, QWidget* parent)
 {
 	KeySequenceDialog dlg (item->sequence(), parent);
@@ -754,8 +745,8 @@
 	return true;
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void KeySequenceDialog::updateOutput()
 {
 	QString shortcut = seq.toString();
@@ -767,8 +758,8 @@
 	lb_output->setText (text);
 }
 
-// =============================================================================
-// =============================================================================
+//
+//
 void KeySequenceDialog::keyPressEvent (QKeyEvent* ev)
 {
 	seq = ev->key() + ev->modifiers();
--- a/src/partDownloader.cc	Sun Jun 22 21:13:50 2014 +0300
+++ b/src/partDownloader.cc	Sun Jun 29 15:22:43 2014 +0300
@@ -61,9 +61,8 @@
 {
 	QString path = cfg::downloadFilePath;
 
-#if DIRSLASH_CHAR != '/'
-	path.replace (DIRSLASH, "/");
-#endif
+	if (DIRSLASH[0] != '/')
+		path.replace (DIRSLASH, "/");
 
 	return path;
 }
@@ -270,7 +269,7 @@
 		if (not req->isFinished())
 			return;
 
-		if (req->state() == PartDownloadRequest::EFailed)
+		if (req->state() == DLRQ_Failed)
 			failed = true;
 	}
 
@@ -324,7 +323,7 @@
 //
 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) :
 	QObject (parent),
-	m_state (ERequesting),
+	m_state (DLRQ_Requesting),
 	m_prompt (parent),
 	m_url (url),
 	m_destinaton (dest),
@@ -362,15 +361,15 @@
 //
 void PartDownloadRequest::updateToTable()
 {
-	const int		labelcol = PartDownloader::PartLabelColumn,
-					progcol = PartDownloader::ProgressColumn;
-	QTableWidget*	table = prompt()->interface()->progress;
-	QProgressBar*	prog;
+	int const labelcol = PartDownloader::PartLabelColumn;
+	int const progcol = PartDownloader::ProgressColumn;
+	QTableWidget* table = prompt()->interface()->progress;
+	QProgressBar* prog;
 
 	switch (state())
 	{
-		case ERequesting:
-		case EDownloading:
+		case DLRQ_Requesting:
+		case DLRQ_Downloading:
 		{
 			prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol));
 
@@ -384,10 +383,10 @@
 			prog->setValue (numBytesRead());
 		} break;
 
-		case EFinished:
-		case EFailed:
+		case DLRQ_Finished:
+		case DLRQ_Failed:
 		{
-			const QString text = (state() == EFinished)
+			const QString text = (state() == DLRQ_Finished)
 				? "<b><span style=\"color: #080\">FINISHED</span></b>"
 				: "<b><span style=\"color: #800\">FAILED</span></b>";
 
@@ -421,10 +420,10 @@
 		if (isPrimary() && not prompt()->isAborted())
 			critical (networkReply()->errorString());
 
-		setState (EFailed);
+		setState (DLRQ_Failed);
 	}
-	elif (state() != EFailed)
-		setState (EFinished);
+	elif (state() != DLRQ_Failed)
+		setState (DLRQ_Finished);
 
 	setNumBytesRead (numBytesTotal());
 	updateToTable();
@@ -435,11 +434,11 @@
 		delete filePointer();
 		setFilePointer (null);
 
-		if (state() == EFailed)
+		if (state() == DLRQ_Failed)
 			QFile::remove (filePath());
 	}
 
-	if (state() != EFinished)
+	if (state() != DLRQ_Finished)
 	{
 		prompt()->checkIfFinished();
 		return;
@@ -482,7 +481,7 @@
 {
 	setNumBytesRead (recv);
 	setNumBytesTotal (total);
-	setState (EDownloading);
+	setState (DLRQ_Downloading);
 	updateToTable();
 }
 
@@ -490,7 +489,7 @@
 //
 void PartDownloadRequest::readyRead()
 {
-	if (state() == EFailed)
+	if (state() == DLRQ_Failed)
 		return;
 
 	if (filePointer() == null)
@@ -504,7 +503,7 @@
 		if (not filePointer()->open (QIODevice::WriteOnly))
 		{
 			critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno)));
-			setState (EFailed);
+			setState (DLRQ_Failed);
 			networkReply()->abort();
 			updateToTable();
 			prompt()->checkIfFinished();
@@ -519,7 +518,7 @@
 //
 bool PartDownloadRequest::isFinished() const
 {
-	return state() == EFinished || state() == EFailed;
+	return state() == DLRQ_Finished || state() == DLRQ_Failed;
 }
 
 // =============================================================================
--- a/src/partDownloader.h	Sun Jun 22 21:13:50 2014 +0300
+++ b/src/partDownloader.h	Sun Jun 29 15:22:43 2014 +0300
@@ -86,43 +86,43 @@
 
 // =============================================================================
 //
+enum PartDownloadRequestState
+{
+	DLRQ_Requesting,
+	DLRQ_Downloading,
+	DLRQ_Finished,
+	DLRQ_Failed,
+};
+
 class PartDownloadRequest : public QObject
 {
-	public:
-		enum EState
-		{
-			ERequesting,
-			EDownloading,
-			EFinished,
-			EFailed,
-		};
+public:
+	Q_OBJECT
+	PROPERTY (public,	int,						tableRow,		setTableRow,		STOCK_WRITE)
+	PROPERTY (private,	PartDownloadRequestState,	state,			setState,			STOCK_WRITE)
+	PROPERTY (private,	PartDownloader*,			prompt,			setPrompt,			STOCK_WRITE)
+	PROPERTY (private,	QString,					url,			setURL,				STOCK_WRITE)
+	PROPERTY (private,	QString,					destinaton,		setDestination,		STOCK_WRITE)
+	PROPERTY (private,	QString,					filePath,		setFilePath,		STOCK_WRITE)
+	PROPERTY (private,	QNetworkAccessManager*,		networkManager,	setNetworkManager,	STOCK_WRITE)
+	PROPERTY (private,	QNetworkReply*,				networkReply,	setNetworkReply,	STOCK_WRITE)
+	PROPERTY (private,	bool,						isFirstUpdate,	setFirstUpdate,		STOCK_WRITE)
+	PROPERTY (private,	int64,						numBytesRead,	setNumBytesRead,	STOCK_WRITE)
+	PROPERTY (private,	int64,						numBytesTotal,	setNumBytesTotal,	STOCK_WRITE)
+	PROPERTY (private,	bool,						isPrimary,		setPrimary,			STOCK_WRITE)
+	PROPERTY (private,	QFile*,						filePointer,	setFilePointer,		STOCK_WRITE)
 
-		Q_OBJECT
-		PROPERTY (public,	int,					tableRow,		setTableRow,		STOCK_WRITE)
-		PROPERTY (private,	EState,					state,			setState,			STOCK_WRITE)
-		PROPERTY (private,	PartDownloader*,		prompt,			setPrompt,			STOCK_WRITE)
-		PROPERTY (private,	QString,				url,			setURL,				STOCK_WRITE)
-		PROPERTY (private,	QString,				destinaton,		setDestination,		STOCK_WRITE)
-		PROPERTY (private,	QString,				filePath,		setFilePath,		STOCK_WRITE)
-		PROPERTY (private,	QNetworkAccessManager*,	networkManager,	setNetworkManager,	STOCK_WRITE)
-		PROPERTY (private,	QNetworkReply*,			networkReply,	setNetworkReply,	STOCK_WRITE)
-		PROPERTY (private,	bool,					isFirstUpdate,	setFirstUpdate,		STOCK_WRITE)
-		PROPERTY (private,	int64,					numBytesRead,	setNumBytesRead,	STOCK_WRITE)
-		PROPERTY (private,	int64,					numBytesTotal,	setNumBytesTotal,	STOCK_WRITE)
-		PROPERTY (private,	bool,					isPrimary,		setPrimary,			STOCK_WRITE)
-		PROPERTY (private,	QFile*,					filePointer,	setFilePointer,		STOCK_WRITE)
+public:
+	explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
+	PartDownloadRequest (const PartDownloadRequest&) = delete;
+	virtual ~PartDownloadRequest();
+	void updateToTable();
+	bool isFinished() const;
+	void operator= (const PartDownloadRequest&) = delete;
 
-	public:
-		explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent);
-		PartDownloadRequest (const PartDownloadRequest&) = delete;
-		virtual ~PartDownloadRequest();
-		void updateToTable();
-		bool isFinished() const;
-		void operator= (const PartDownloadRequest&) = delete;
-
-	public slots:
-		void downloadFinished();
-		void readyRead();
-		void downloadProgress (qint64 recv, qint64 total);
-		void abort();
+public slots:
+	void downloadFinished();
+	void readyRead();
+	void downloadProgress (qint64 recv, qint64 total);
+	void abort();
 };

mercurial