r22889 by jghali - Some refactoring for character palette
scribus-commit
scribus-commit at lists.scribus.net
Tue Mar 12 11:32:14 UTC 2019
Author: jghali
Date: Tue Mar 12 11:32:14 2019
New Revision: 22889
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22889
Log:
Some refactoring for character palette
Modified:
trunk/Scribus/scribus/ui/charselect.cpp
Modified: trunk/Scribus/scribus/ui/charselect.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22889&path=/trunk/Scribus/scribus/ui/charselect.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/charselect.cpp (original)
+++ trunk/Scribus/scribus/ui/charselect.cpp Tue Mar 12 11:32:14 2019
@@ -21,8 +21,6 @@
#include "ui/scmessagebox.h"
#include "util.h"
#include "iconmanager.h"
-
-
CharSelect::CharSelect(QWidget* parent) : ScrPaletteBase(parent, "CharSelect"), m_doc(nullptr), m_enhanced(nullptr), m_Item(nullptr)
{
@@ -255,48 +253,47 @@
void CharSelect::uniLoadButton_clicked()
{
QString f = QFileDialog::getOpenFileName(this, tr("Open Character Palette"), QDir::currentPath(), paletteFileMask);
- if (!f.isNull())
+ if (!f.isEmpty())
loadUserContent(f);
}
void CharSelect::loadUserContent(const QString& f)
{
-// tDebug("loadUserContent start");
QFile file(f);
if (!file.exists())
return;
- if (file.open(QIODevice::ReadOnly))
- {
- QTextStream stream(&file);
- QString line = stream.readLine();
- if (line != "# Character palette file for Scribus")
+ if (!file.open(QIODevice::ReadOnly))
+ return;
+
+ QTextStream stream(&file);
+ QString line = stream.readLine();
+ if (line != "# Character palette file for Scribus")
+ {
+ file.close();
+ return;
+ }
+
+ m_userTableModel->setCharacters(CharClassDef());
+ while (!stream.atEnd())
+ {
+ bool ok = false;
+ line = stream.readLine();
+ if (line.left(1) == "#")
+ continue; // don't mess with a comment
+ int a = line.indexOf(" ");
+ QString si = line.left(a);
+ si.toInt(&ok, 10);
+ if (ok)
+ m_userTableModel->addCharacter(line);
+ else
{
- file.close();
- return;
+ ScMessageBox::warning(this, tr("Error"),
+ "<qt>" + tr("Error reading file %1 - file is corrupted propably.").arg(f) + "</qt>",
+ QMessageBox::Ok, QMessageBox::NoButton);
+ break;
}
- m_userTableModel->setCharacters(CharClassDef());
- while (!stream.atEnd())
- {
- bool ok = false;
- line = stream.readLine();
- if (line.left(1) == "#")
- continue; // don't mess with a comment
- int a = line.indexOf(" ");
- QString si = line.left(a);
- si.toInt(&ok, 10);
- if (ok)
- m_userTableModel->addCharacter(line);
- else
- {
- ScMessageBox::warning(this, tr("Error"),
- "<qt>" + tr("Error reading file %1 - file is corrupted propably.").arg(f) + "</qt>",
- QMessageBox::Ok, QMessageBox::NoButton);
- break;
- }
- }
- file.close();
- }
-// tDebug("loadUserContent end");
+ }
+ file.close();
}
void CharSelect::uniSaveButton_clicked()
@@ -304,10 +301,10 @@
if (m_userTableModel->characters().count() == 0)
return;
QString f = QFileDialog::getSaveFileName(this, tr("Save Quick Character Palette"), QDir::currentPath(), paletteFileMask);
- if (f.isNull())
+ if (f.isEmpty())
return;
if (!f.endsWith(".ucp"))
- f+=".ucp";
+ f += ".ucp";
//#9832: Qt does this for us now in getSaveFileName
// if (!overwrite(this, f))
// return;
@@ -317,22 +314,23 @@
void CharSelect::saveUserContent(const QString& f)
{
QFile file(f);
- if (file.open(QIODevice::WriteOnly))
- {
- QTextStream stream(&file);
- CharClassDef chars = m_userTableModel->characters();
- QStringList fonts = m_userTableModel->fonts();
- stream << "# Character palette file for Scribus\n";
- for (int a = 0; a < chars.count(); a++)
- {
- stream << chars[a] << " " << fonts[a] << "\n";
- }
- file.close();
- }
- else
+ if (!file.open(QIODevice::WriteOnly))
+ {
ScMessageBox::warning(this, tr("Error"),
- "<qt>" + tr("Cannot write file %1").arg(f) + "</qt>",
- QMessageBox::Ok, QMessageBox::NoButton);
+ "<qt>" + tr("Cannot write file %1").arg(f) + "</qt>",
+ QMessageBox::Ok, QMessageBox::NoButton);
+ return;
+ }
+
+ QTextStream stream(&file);
+ CharClassDef chars = m_userTableModel->characters();
+ QStringList fonts = m_userTableModel->fonts();
+ stream << "# Character palette file for Scribus\n";
+ for (int a = 0; a < chars.count(); a++)
+ {
+ stream << chars[a] << " " << fonts[a] << "\n";
+ }
+ file.close();
}
void CharSelect::uniClearButton_clicked()
More information about the scribus-commit
mailing list