Skip to content

Commit

Permalink
Merge pull request #1 from Diadlo/fixSave
Browse files Browse the repository at this point in the history
Fix save for document with name
  • Loading branch information
lintest committed Aug 23, 2020
2 parents 5a37885 + b80ce65 commit 6d9f937
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 60 deletions.
4 changes: 4 additions & 0 deletions fb2edit.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ QT += webkit
QT += network
QT += xmlpatterns

CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11
DEFINES += QT_USE_QSTRINGBUILDER

OTHER_FILES += \
source/res/style.css \
source/res/blank.fb2 \
Expand Down
2 changes: 1 addition & 1 deletion source/fb2app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *argv[])
app.installTranslator(&translator);

int count = app.arguments().count();
for (int i = 1; i < count; i++) {
for (int i = 1; i < count; ++i) {
QString arg = app.arguments().at(i);
(new FbMainWindow(arg))->show();
}
Expand Down
10 changes: 5 additions & 5 deletions source/fb2code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ void FbHighlighter::highlightBlock(const QString& text)
return;
}
}

for (; i < text.length(); i++)
const int len = text.length();
for (; i < len; ++i)
{
switch (text.at(i).toAscii())
{
case '<':
brackets++;
++brackets;
if (brackets == 1)
{
setFormat(i, 1, fmtSyntaxChar);
Expand All @@ -255,7 +255,7 @@ void FbHighlighter::highlightBlock(const QString& text)
break;

case '>':
brackets--;
--brackets;
if (brackets == 0)
{
setFormat(i, 1, fmtSyntaxChar);
Expand Down Expand Up @@ -345,7 +345,7 @@ void FbHighlighter::highlightBlock(const QString& text)
setFormat(iLength - 3, 3, fmtSyntaxChar);
i += iLength - 2; // skip comment
state = NoState;
brackets--;
--brackets;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion source/fb2dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void FbMainDock::addMenu(QMenu *menu)

void FbMainDock::enableMenu(bool value)
{
foreach (QMenu *menu, m_menus) {
for (QMenu *menu: m_menus) {
menu->setEnabled(value);
}
}
13 changes: 7 additions & 6 deletions source/fb2head.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ QString FbScheme::type() const
QString result = attribute("type");
if (!result.isEmpty()) return result;
FbScheme child = firstChildElement("xs:complexType").firstChildElement();
QString tag;
while (!child.isNull()) {
QString tag = child.tagName();
tag = child.tagName();
if (tag == "xs:complexContent" || tag == "xs:simpleContent") {
return child.firstChildElement("xs:extension").attribute("base");
}
Expand Down Expand Up @@ -231,7 +232,7 @@ FbHeadItem::FbHeadItem(QWebElement &element, FbHeadItem *parent)

FbHeadItem::~FbHeadItem()
{
foreach (FbHeadItem * item, m_list) {
for (FbHeadItem * item: m_list) {
delete item;
}
}
Expand Down Expand Up @@ -319,7 +320,7 @@ QString FbHeadItem::value() const
} break;
case Cover: {
QString text;
foreach (FbHeadItem * item, m_list) {
for (FbHeadItem * item: m_list) {
if (item->m_name == "image") {
if (!text.isEmpty()) text += ", ";
text += item->value();
Expand Down Expand Up @@ -381,7 +382,7 @@ bool FbHeadItem::canEditExtra() const

QString FbHeadItem::sub(const QString &key) const
{
foreach (FbHeadItem * item, m_list) {
for (FbHeadItem * item: m_list) {
if (item->m_name == key) return item->value();
}
return QString();
Expand Down Expand Up @@ -424,13 +425,13 @@ void FbHeadModel::expand(QTreeView *view)
{
QModelIndex parent = QModelIndex();
int count = rowCount(parent);
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
QModelIndex child = index(i, 0, parent);
FbHeadItem *node = item(child);
if (!node) continue;
view->expand(child);
int count = rowCount(child);
for (int j = 0; j < count; j++) {
for (int j = 0; j < count; ++j) {
QModelIndex ch = index(j, 0, child);
FbHeadItem *node = item(ch);
if (node) view->expand(ch);
Expand Down
14 changes: 7 additions & 7 deletions source/fb2html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FbTextElement::Sublist::Sublist(const TypeList &list, const QString &name)
{
while (m_pos != list.end()) {
if (m_pos->name() == name) break;
m_pos++;
++m_pos;
}
}

Expand All @@ -88,7 +88,7 @@ bool FbTextElement::Sublist::operator <(const FbTextElement &element) const
{
if (element.isNull()) return true;
const QString name = element.tagName();
for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); ++it) {
if (it->name() == name) return m_pos < it;
}
return false;
Expand Down Expand Up @@ -142,7 +142,7 @@ int FbTextElement::childIndex() const
FbElementList::const_iterator it;
for (it = list.constBegin(); it != list.constEnd(); ++it) {
if (*it == *this) return result;
result++;
++result;
}
return -1;
}
Expand All @@ -161,7 +161,7 @@ const FbTextElement::TypeList * FbTextElement::subtypes() const
bool FbTextElement::hasSubtype(const QString &style) const
{
if (const TypeList * list = subtypes()) {
for (TypeList::const_iterator item = list->begin(); item != list->end(); item++) {
for (TypeList::const_iterator item = list->begin(); item != list->end(); ++item) {
if (item->name() == style) return true;
}
}
Expand All @@ -170,7 +170,7 @@ bool FbTextElement::hasSubtype(const QString &style) const

FbTextElement::TypeList::const_iterator FbTextElement::subtype(const TypeList &list, const QString &style)
{
for (TypeList::const_iterator item = list.begin(); item != list.end(); item++) {
for (TypeList::const_iterator item = list.begin(); item != list.end(); ++item) {
if (item->name() == style) return item;
}
return list.end();
Expand Down Expand Up @@ -253,7 +253,7 @@ int FbTextElement::index() const
FbTextElement prior = *this;
while (!prior.isNull()) {
prior = prior.previousSibling();
result++;
++result;
}
return result;
}
Expand All @@ -263,7 +263,7 @@ FbTextElement FbTextElement::child(int index) const
FbTextElement result = firstChild();
while (index > 0) {
result = result.nextSibling();
index--;
--index;
}
return index ? FbTextElement() : result;
}
Expand Down
2 changes: 1 addition & 1 deletion source/fb2imgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ QString FbStore::newName(const QString &path)
if (!exists(name)) return name;
QString base = info.baseName();
QString suff = info.suffix();
for (int i = 1; ; i++) {
for (int i = 1; ; ++i) {
QString name = QString("%1(%2).%3").arg(base).arg(i).arg(suff);
if (exists(name)) continue;
return name;
Expand Down
2 changes: 1 addition & 1 deletion source/fb2logs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ QVariant FbLogModel::FbLogItem::icon() const
FbLogModel::FbLogModel(QObject *parent)
: QAbstractListModel(parent)
{
foreach (FbLogItem *item, m_list) delete item;
for (FbLogItem *item: m_list) delete item;
}

QVariant FbLogModel::data(const QModelIndex &index, int role) const
Expand Down
11 changes: 8 additions & 3 deletions source/fb2main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void FbMainWindow::fileNew()
void FbMainWindow::fileOpen()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), "Fiction book files (*.fb2)");
if (filename.isEmpty()) return;
if (filename.isEmpty()) {
return;
}

FbMainWindow * existing = findFbMainWindow(filename);
if (existing) {
Expand All @@ -118,6 +120,7 @@ void FbMainWindow::fileOpen()
if (isUntitled && !isWindowModified()) {
mainDock->load(filename);
setCurrentFile(filename);
isUntitled = false;
} else {
FbMainWindow * other = new FbMainWindow(filename, FB2);
other->mainDock->load(filename);
Expand All @@ -129,7 +132,9 @@ void FbMainWindow::fileOpen()
bool FbMainWindow::fileSave()
{
if (isUntitled) {
return fileSaveAs();
bool success = fileSaveAs();
isUntitled = success;
return success;
} else {
return saveFile(curFile);
}
Expand Down Expand Up @@ -600,7 +605,7 @@ FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
{
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();

foreach (QWidget *widget, qApp->topLevelWidgets()) {
for (QWidget *widget: qApp->topLevelWidgets()) {
FbMainWindow *mainWin = qobject_cast<FbMainWindow *>(widget);
if (mainWin && mainWin->curFile == canonicalFilePath)
return mainWin;
Expand Down
4 changes: 2 additions & 2 deletions source/fb2mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

void FbActionMap::connect()
{
foreach (QAction *action, *this) {
for (QAction *action: *this) {
action->setEnabled(true);
}
}

void FbActionMap::disconnect()
{
foreach (QAction *action, *this) {
for (QAction *action: *this) {
if (action->isCheckable()) action->setChecked(false);
action->setEnabled(false);
action->disconnect();
Expand Down
2 changes: 1 addition & 1 deletion source/fb2read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void FbReadHandler::TextHandler::Init(const QString &name, const QXmlAttributes
Keyword key = toKeyword(name);
writer().writeStartElement(m_tag);
int count = atts.count();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
QString name = atts.qName(i);
switch (key) {
case Anchor: { if (atts.localName(i) == "href") name = "href"; break; }
Expand Down
2 changes: 1 addition & 1 deletion source/fb2read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FbReadThread : public QThread

public:
static void execute(QObject *parent, QXmlInputSource *source, QIODevice *device);
~FbReadThread();
virtual ~FbReadThread();

signals:
void binary(const QString &name, const QByteArray &data);
Expand Down

0 comments on commit 6d9f937

Please sign in to comment.