Patches
Yuriy Skalko
yuriy.skalko at gmail.com
Fri Oct 23 11:13:19 UTC 2020
Here are my new refactoring patches.
Yuriy
-------------- next part --------------
From 3693c544e718f6c3e4cf43ac48d006706b2eecc6 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Wed, 21 Oct 2020 11:35:40 +0300
Subject: [PATCH 1/3] Constify
---
src/Box.cpp | 2 +-
src/Box.h | 2 +-
src/Buffer.cpp | 2 +-
src/Buffer.h | 2 +-
src/Compare.cpp | 2 +-
src/Converter.cpp | 6 +++---
src/Converter.h | 6 +++---
src/Cursor.cpp | 6 +++---
src/Cursor.h | 8 ++++----
src/DispatchResult.h | 2 +-
src/FuncRequest.h | 2 +-
src/LaTeX.h | 2 +-
src/Paragraph.cpp | 12 ++++++------
src/Server.h | 2 +-
src/TocBackend.cpp | 2 +-
src/TocBackend.h | 2 +-
src/frontends/WorkAreaManager.cpp | 2 +-
src/frontends/WorkAreaManager.h | 2 +-
src/mathed/MacroTable.h | 2 +-
src/tex2lyx/Parser.cpp | 2 +-
src/tex2lyx/Parser.h | 2 +-
21 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/src/Box.cpp b/src/Box.cpp
index a3461ef3ea..28d2caa01c 100644
--- a/src/Box.cpp
+++ b/src/Box.cpp
@@ -31,7 +31,7 @@ Box::Box(int x1_, int x2_, int y1_, int y2_)
{}
-bool Box::contains(int x, int y)
+bool Box::contains(int x, int y) const
{
return (x1 < x && x2 > x && y1 < y && y2 > y);
}
diff --git a/src/Box.h b/src/Box.h
index c362fa6a38..9522ad0a79 100644
--- a/src/Box.h
+++ b/src/Box.h
@@ -42,7 +42,7 @@ public:
* the box. Check is exclusive (point on a border
* returns false).
*/
- bool contains(int x, int y);
+ bool contains(int x, int y) const;
};
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 9ba2373ea4..d25aa03fb8 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1610,7 +1610,7 @@ bool Buffer::writeFile(FileName const & fname) const
}
-docstring Buffer::emergencyWrite()
+docstring Buffer::emergencyWrite() const
{
// No need to save if the buffer has not changed.
if (isClean())
diff --git a/src/Buffer.h b/src/Buffer.h
index f65d31d654..a917c6e9f7 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -259,7 +259,7 @@ public:
bool autoSave() const;
/// save emergency file
/// \return a status message towards the user.
- docstring emergencyWrite();
+ docstring emergencyWrite() const;
//FIXME:The following function should be private
//private:
diff --git a/src/Compare.cpp b/src/Compare.cpp
index 49bdac1bfa..51a28f16ec 100644
--- a/src/Compare.cpp
+++ b/src/Compare.cpp
@@ -107,7 +107,7 @@ public:
: o(o_), n(n_)
{}
- bool operator!=(DocPair const & rhs)
+ bool operator!=(DocPair const & rhs) const
{
// this might not be intuitive but correct for our purpose
return o != rhs.o && n != rhs.n;
diff --git a/src/Converter.cpp b/src/Converter.cpp
index ada329e5d9..747dd88ada 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -259,7 +259,7 @@ void Converters::updateLast(Formats const & formats)
OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path,
- Buffer const * buffer)
+ Buffer const * buffer) const
{
for (auto const & edge : path) {
Converter const & conv = converterlist_[edge];
@@ -283,7 +283,7 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path,
}
-string Converters::getHyperrefDriver(Graph::EdgePath const & path)
+string Converters::getHyperrefDriver(Graph::EdgePath const & path) const
{
for (auto const & edge : path) {
Converter const & conv = converterlist_[edge];
@@ -818,7 +818,7 @@ bool Converters::move(string const & fmt,
}
-bool Converters::formatIsUsed(string const & format)
+bool Converters::formatIsUsed(string const & format) const
{
for (auto const & cvt : converterlist_) {
if (cvt.from() == format || cvt.to() == format)
diff --git a/src/Converter.h b/src/Converter.h
index e9efa00f4f..b9ee3292bb 100644
--- a/src/Converter.h
+++ b/src/Converter.h
@@ -176,9 +176,9 @@ public:
Graph::EdgePath getPath(std::string const & from, std::string const & to);
///
OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path,
- Buffer const * buffer = nullptr);
+ Buffer const * buffer = nullptr) const;
///
- std::string getHyperrefDriver(Graph::EdgePath const & path);
+ std::string getHyperrefDriver(Graph::EdgePath const & path) const;
/// Flags for converting files
enum ConversionFlags {
/// No special flags
@@ -199,7 +199,7 @@ public:
///
void updateLast(Formats const & formats);
///
- bool formatIsUsed(std::string const & format);
+ bool formatIsUsed(std::string const & format) const;
///
const_iterator begin() const { return converterlist_.begin(); }
///
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 7197b91cf2..9e7867c8d3 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -502,7 +502,7 @@ void CursorData::clearSelection()
}
-int CursorData::countInsetsInSelection(InsetCode const & inset_code)
+int CursorData::countInsetsInSelection(InsetCode const & inset_code) const
{
if (!selection_)
return 0;
@@ -528,7 +528,7 @@ int CursorData::countInsetsInSelection(InsetCode const & inset_code)
}
-bool CursorData::insetInSelection(InsetCode const & inset_code)
+bool CursorData::insetInSelection(InsetCode const & inset_code) const
{
if (!selection_)
return false;
@@ -669,7 +669,7 @@ void CursorData::recordUndoSelection() const
}
-int CursorData::currentMode()
+int CursorData::currentMode() const
{
LASSERT(!empty(), return Inset::UNDECIDED_MODE);
for (int i = depth() - 1; i >= 0; --i) {
diff --git a/src/Cursor.h b/src/Cursor.h
index fc4daeb93b..951a0cc4db 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -118,7 +118,7 @@ public:
///
void setWordSelection(bool set) { word_selection_ = set; }
///
- bool wordSelection() { return word_selection_; }
+ bool wordSelection() const { return word_selection_; }
/// did we place the anchor?
bool mark() const { return mark_; }
/// did we place the anchor?
@@ -131,10 +131,10 @@ public:
void clearSelection();
/// check whether selection contains specific type of inset
/// returns 0 if no selection was made
- bool insetInSelection(InsetCode const & inset);
+ bool insetInSelection(InsetCode const & inset) const;
/// count occurences of specific inset type in the selection
/// returns 0 if no selection was made
- int countInsetsInSelection(InsetCode const & inset);
+ int countInsetsInSelection(InsetCode const & inset) const;
/// access to normalized selection anchor
CursorSlice normalAnchor() const;
@@ -207,7 +207,7 @@ public:
DocIterator newWord() const { return new_word_; }
/// are we in math mode (2), text mode (1) or unsure (0)?
- int currentMode();
+ int currentMode() const;
/// Return true if the next or previous inset has confirmDeletion depending
/// on the boolean before. If there is a selection, return true if at least
diff --git a/src/DispatchResult.h b/src/DispatchResult.h
index d8689898d8..ac1eb6c821 100644
--- a/src/DispatchResult.h
+++ b/src/DispatchResult.h
@@ -48,7 +48,7 @@ public:
///
void setError(bool e) { error_ = e; }
///
- docstring message() { return message_; }
+ docstring message() const { return message_; }
///
void setMessage(docstring const & m) { message_ = m; }
///
diff --git a/src/FuncRequest.h b/src/FuncRequest.h
index 42829ae8de..19f571a091 100644
--- a/src/FuncRequest.h
+++ b/src/FuncRequest.h
@@ -86,7 +86,7 @@ public:
///
mouse_button::state button() const { return button_; }
///
- KeyModifier modifier() { return modifier_; }
+ KeyModifier modifier() const { return modifier_; }
/// argument parsing, extract argument i as std::string
std::string getArg(unsigned int i) const;
diff --git a/src/LaTeX.h b/src/LaTeX.h
index c57b03b830..994fbe07ff 100644
--- a/src/LaTeX.h
+++ b/src/LaTeX.h
@@ -185,7 +185,7 @@ public:
int run(TeXErrors &);
///
- int getNumErrors() { return num_errors;}
+ int getNumErrors() const { return num_errors;}
///
int scanLogFile(TeXErrors &);
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 98e051445e..fe31d01a60 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -360,19 +360,19 @@ public:
char_type const c,
otexstream & os,
pos_type i,
- unsigned int & column);
+ unsigned int & column) const;
///
bool latexSpecialTU(
char_type const c,
otexstream & os,
pos_type i,
- unsigned int & column);
+ unsigned int & column) const;
///
bool latexSpecialT3(
char_type const c,
otexstream & os,
pos_type i,
- unsigned int & column);
+ unsigned int & column) const;
///
void validate(LaTeXFeatures & features) const;
@@ -1317,7 +1317,7 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
bool Paragraph::Private::latexSpecialT1(char_type const c, otexstream & os,
- pos_type i, unsigned int & column)
+ pos_type i, unsigned int & column) const
{
switch (c) {
case '>':
@@ -1345,7 +1345,7 @@ bool Paragraph::Private::latexSpecialT1(char_type const c, otexstream & os,
bool Paragraph::Private::latexSpecialTU(char_type const c, otexstream & os,
- pos_type i, unsigned int & column)
+ pos_type i, unsigned int & column) const
{
// TU encoding is currently on par with T1.
return latexSpecialT1(c, os, i, column);
@@ -1353,7 +1353,7 @@ bool Paragraph::Private::latexSpecialTU(char_type const c, otexstream & os,
bool Paragraph::Private::latexSpecialT3(char_type const c, otexstream & os,
- pos_type /*i*/, unsigned int & column)
+ pos_type /*i*/, unsigned int & column) const
{
switch (c) {
case '*':
diff --git a/src/Server.h b/src/Server.h
index 40021daa41..e20406a6d4 100644
--- a/src/Server.h
+++ b/src/Server.h
@@ -104,7 +104,7 @@ public:
#endif
/// Tell whether we asked another instance of LyX to open the files
- bool deferredLoading() { return deferred_loading_; }
+ bool deferredLoading() const { return deferred_loading_; }
private:
/// the filename of the in pipe
diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
index 500d5e3ce0..d9ed95767a 100644
--- a/src/TocBackend.cpp
+++ b/src/TocBackend.cpp
@@ -153,7 +153,7 @@ TocBuilder & TocBackend::builder(string const & type)
// TocItem creation and update should be made in a dedicated function and
// updateItem should be rewritten to uniformly update the matching items from
// all TOCs.
-bool TocBackend::updateItem(DocIterator const & dit_in)
+bool TocBackend::updateItem(DocIterator const & dit_in) const
{
// we need a text
DocIterator dit = dit_in.getInnerText();
diff --git a/src/TocBackend.h b/src/TocBackend.h
index 026f4f879b..b67ee60da3 100644
--- a/src/TocBackend.h
+++ b/src/TocBackend.h
@@ -116,7 +116,7 @@ public:
///
void reset();
/// \return true if the item was updated.
- bool updateItem(DocIterator const & pit);
+ bool updateItem(DocIterator const & pit) const;
///
TocList const & tocs() const { return tocs_; }
/// never null
diff --git a/src/frontends/WorkAreaManager.cpp b/src/frontends/WorkAreaManager.cpp
index c79f08bef7..0d1d189cf2 100644
--- a/src/frontends/WorkAreaManager.cpp
+++ b/src/frontends/WorkAreaManager.cpp
@@ -47,7 +47,7 @@ void WorkAreaManager::closeAll()
}
-bool WorkAreaManager::unhide(Buffer * buf)
+bool WorkAreaManager::unhide(Buffer * buf) const
{
if (!work_areas_.empty())
return true;
diff --git a/src/frontends/WorkAreaManager.h b/src/frontends/WorkAreaManager.h
index 0434074ab4..cd716fc087 100644
--- a/src/frontends/WorkAreaManager.h
+++ b/src/frontends/WorkAreaManager.h
@@ -46,7 +46,7 @@ public:
void updateTitles();
/// If there is no work area, create a new one in the current view using the
/// buffer buf. Returns false if not possible.
- bool unhide(Buffer * buf);
+ bool unhide(Buffer * buf) const;
private:
typedef std::list<WorkArea *>::iterator iterator;
diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h
index e83be84b75..b588ee2cf9 100644
--- a/src/mathed/MacroTable.h
+++ b/src/mathed/MacroTable.h
@@ -73,7 +73,7 @@ public:
///
void setSymbol(latexkeys const * sym) { sym_ = sym; }
///
- DocIterator const & pos() { return pos_; }
+ DocIterator const & pos() const { return pos_; }
/// lock while being drawn to avoid recursions
int lock() const { return ++lockCount_; }
diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index 62cab06fba..57253650f7 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -443,7 +443,7 @@ void Parser::dropPosition()
}
-bool Parser::good()
+bool Parser::good() const
{
if (pos_ < tokens_.size())
return true;
diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h
index ada6b5f72a..41384599c2 100644
--- a/src/tex2lyx/Parser.h
+++ b/src/tex2lyx/Parser.h
@@ -334,7 +334,7 @@ public:
/// Is any further input pending()? This is not like
/// std::istream::good(), which returns true if all available input
/// was read, and the next attempt to read would return EOF.
- bool good();
+ bool good() const;
/// resets the parser to initial state
void reset();
--
2.28.0.windows.1
-------------- next part --------------
From f4fbd0d81c86b1ab182da1db6859da827fad8cc1 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Wed, 21 Oct 2020 10:23:43 +0300
Subject: [PATCH 2/3] Small refactorings
---
src/Text.cpp | 2 +-
src/graphics/GraphicsCache.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Text.cpp b/src/Text.cpp
index 5d761ca134..0bb66f6666 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1127,7 +1127,7 @@ void Text::charInserted(Cursor & cur)
&& par.isWordSeparator(cur.pos() - 1)) {
// get the word in front of cursor
LBUFERR(this == cur.text());
- cur.paragraph().updateWords();
+ par.updateWords();
}
}
diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp
index dbf9cafa5e..5762e4f1e2 100644
--- a/src/graphics/GraphicsCache.cpp
+++ b/src/graphics/GraphicsCache.cpp
@@ -110,7 +110,7 @@ void Cache::add(FileName const & file, FileName const & doc_file) const
return;
}
- pimpl_->cache[file] = ItemPtr(new CacheItem(file, doc_file));
+ pimpl_->cache[file] = std::make_shared<CacheItem>(file, doc_file);
}
--
2.28.0.windows.1
-------------- next part --------------
From 8614f280f5f39e45557d4ac6e0f531cdff1ef954 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Fri, 23 Oct 2020 13:40:41 +0300
Subject: [PATCH 3/3] Fix obsoleted Qt values
All new values exist in Qt 4.8.7.
---
src/frontends/qt/FileDialog.cpp | 3 ++-
src/frontends/qt/qt_helpers.cpp | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/frontends/qt/FileDialog.cpp b/src/frontends/qt/FileDialog.cpp
index fb05f43e55..1491939a99 100644
--- a/src/frontends/qt/FileDialog.cpp
+++ b/src/frontends/qt/FileDialog.cpp
@@ -188,7 +188,8 @@ FileDialog::Result FileDialog::opendir(QString const & path,
LyXFileDialog dlg(title_, path, QStringList(qt_("Directories")),
private_->b1, private_->b2);
- dlg.setFileMode(QFileDialog::DirectoryOnly);
+ dlg.setFileMode(QFileDialog::Directory);
+ dlg.setOption(QFileDialog::ShowDirsOnly, true);
if (!suggested.isEmpty())
dlg.selectFile(suggested);
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index 2a35897451..d9cc3644e1 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -239,7 +239,7 @@ void setValid(QWidget * widget, bool valid)
widget->setPalette(QPalette());
} else {
QPalette pal = widget->palette();
- pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0));
+ pal.setColor(QPalette::Active, QPalette::WindowText, QColor(255, 0, 0));
widget->setPalette(pal);
}
}
--
2.28.0.windows.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20201023/b642d1d4/attachment-0001.asc>
More information about the lyx-devel
mailing list