mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Adds the threaded Compare class, which will eventually do the comparison between two documents.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31734 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
221bd56fae
commit
18483e6362
@ -45,7 +45,7 @@ if (ASPELL_FOUND)
|
||||
list(APPEND lyx_headers ${TOP_SRC_DIR}/src/AspellChecker.h)
|
||||
endif()
|
||||
|
||||
lyx_automoc(${TOP_SRC_DIR}/src/Server.cpp)
|
||||
lyx_automoc(${TOP_SRC_DIR}/src/Compare.cpp ${TOP_SRC_DIR}/src/Server.cpp)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||
${ZLIB_INCLUDE_DIR} ${QT_INCLUDES})
|
||||
|
@ -47,6 +47,7 @@ src_header_files = Split('''
|
||||
Color.h
|
||||
ColorSet.h
|
||||
ColorCode.h
|
||||
Compare.h
|
||||
CompletionList.h
|
||||
Converter.h
|
||||
ConverterCache.h
|
||||
@ -155,6 +156,7 @@ src_pre_files = Split('''
|
||||
Chktex.cpp
|
||||
CmdDef.cpp
|
||||
Color.cpp
|
||||
Compare.cpp
|
||||
Converter.cpp
|
||||
ConverterCache.cpp
|
||||
CoordCache.cpp
|
||||
|
91
src/Compare.cpp
Normal file
91
src/Compare.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/**
|
||||
* \file Compare.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Vincent van Ravesteijn
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "Compare.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
/**
|
||||
* The implementation of the algorithm that does the comparison
|
||||
* between two documents.
|
||||
*/
|
||||
class Compare::Impl {
|
||||
public:
|
||||
///
|
||||
Impl(Compare const & compare)
|
||||
: compare_(compare), abort_(false)
|
||||
{}
|
||||
|
||||
///
|
||||
~Impl() {}
|
||||
|
||||
/// Set to true to abort the algorithm
|
||||
bool abort_;
|
||||
|
||||
private:
|
||||
/// The thread object, used to emit signals to the GUI
|
||||
Compare const & compare_;
|
||||
};
|
||||
|
||||
|
||||
Compare::Compare(Buffer const * new_buf, Buffer const * old_buf,
|
||||
Buffer * const dest_buf, CompareOptions const & options)
|
||||
: new_buffer(new_buf), old_buffer(old_buf), dest_buffer(dest_buf),
|
||||
options_(options), pimpl_(new Impl(*this))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Compare::run()
|
||||
{
|
||||
if (!dest_buffer || !new_buffer || !old_buffer)
|
||||
return;
|
||||
|
||||
// Copy the buffer params to the new buffer
|
||||
dest_buffer->params() = options_.settings_from_new
|
||||
? new_buffer->params() : old_buffer->params();
|
||||
|
||||
// do the real work
|
||||
if (!doCompare())
|
||||
return;
|
||||
|
||||
finished(pimpl_->abort_);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void Compare::abort()
|
||||
{
|
||||
pimpl_->abort_ = true;
|
||||
condition_.wakeOne();
|
||||
wait();
|
||||
pimpl_->abort_ = false;
|
||||
}
|
||||
|
||||
|
||||
int Compare::doCompare()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#include "moc_Compare.cpp"
|
||||
|
||||
} // namespace lyx
|
108
src/Compare.h
Normal file
108
src/Compare.h
Normal file
@ -0,0 +1,108 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file Compare.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Vincent van Ravesteijn
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef COMPARE_H
|
||||
#define COMPARE_H
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QWaitCondition>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
/**
|
||||
* The options that are used by the Comparison algorithm
|
||||
* and are set in the GuiCompare Dialog.
|
||||
*/
|
||||
class CompareOptions {
|
||||
public:
|
||||
///
|
||||
CompareOptions()
|
||||
: settings_from_new(0)
|
||||
{}
|
||||
|
||||
/// Copy the settings from the new or old document
|
||||
bool settings_from_new;
|
||||
};
|
||||
|
||||
/**
|
||||
* A threaded object that does the Comparison between two documents
|
||||
* and creates a new document with the differences marked with track
|
||||
* changes.
|
||||
*/
|
||||
class Compare : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
Compare(Buffer const * const old_buf, Buffer const * const new_buf,
|
||||
Buffer * const dest_buf, CompareOptions const & options);
|
||||
|
||||
///
|
||||
~Compare() {
|
||||
abort();
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
/// The thread has finished. If the thread is cancelled
|
||||
/// by the user or due to an error \c aborted is true.
|
||||
void finished(bool aborted) const;
|
||||
|
||||
/// Adds \c progress to the value of the progress bar in the dialog
|
||||
void progress(int progress) const ;
|
||||
|
||||
/// Sets the maximum value of the progress bar in the dialog.
|
||||
void progressMax(int max) const;
|
||||
|
||||
public:
|
||||
/// QThread inherited methods
|
||||
//@{
|
||||
void run();
|
||||
//@}
|
||||
|
||||
/// Aborts the thread
|
||||
void abort();
|
||||
|
||||
private:
|
||||
/// Starts the comparison algorithm
|
||||
int doCompare();
|
||||
|
||||
/// The buffer with the differences marked with track changes
|
||||
Buffer * const dest_buffer;
|
||||
/// The old document's buffer
|
||||
Buffer const * const old_buffer;
|
||||
/// The new document's buffer
|
||||
Buffer const * const new_buffer;
|
||||
|
||||
/// The options that are set in the GuiCompare dialog
|
||||
CompareOptions options_;
|
||||
|
||||
///
|
||||
QWaitCondition condition_;
|
||||
|
||||
/// Use the Pimpl idiom to hide the internals.
|
||||
class Impl;
|
||||
///
|
||||
Impl * pimpl_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -94,6 +94,7 @@ SOURCEFILESCORE = \
|
||||
Chktex.cpp \
|
||||
CmdDef.cpp \
|
||||
Color.cpp \
|
||||
Compare.cpp \
|
||||
ConverterCache.cpp \
|
||||
Converter.cpp \
|
||||
CoordCache.cpp \
|
||||
@ -190,6 +191,7 @@ HEADERFILESCORE = \
|
||||
ColorCode.h \
|
||||
Color.h \
|
||||
ColorSet.h \
|
||||
Compare.h \
|
||||
CompletionList.h \
|
||||
ConverterCache.h \
|
||||
Converter.h \
|
||||
@ -297,9 +299,16 @@ liblyxcore_a_SOURCES = $(SOURCEFILESCORE) $(STANDALONEFILES) $(HEADERFILESCORE)
|
||||
|
||||
endif
|
||||
|
||||
######################### Qt stuff ##############################
|
||||
|
||||
MOCHEADER = Compare.h
|
||||
|
||||
if INSTALL_WINDOWS
|
||||
|
||||
MOCHEADER = Server.h
|
||||
MOCHEADER += Server.h
|
||||
MOCFLAG = -D_WIN32
|
||||
|
||||
endif
|
||||
|
||||
MOCEDFILES = $(MOCHEADER:%.h=moc_%.cpp)
|
||||
|
||||
@ -307,12 +316,10 @@ BUILT_SOURCES += $(MOCEDFILES)
|
||||
CLEANFILES += $(MOCEDFILES)
|
||||
|
||||
moc_%.cpp: %.h
|
||||
$(MOC4) -D_WIN32 -o $@ $<
|
||||
$(MOC4) $(MOCFLAG) -o $@ $<
|
||||
|
||||
liblyxcore_a_DEPENDENCIES = $(MOCEDFILES)
|
||||
|
||||
endif
|
||||
|
||||
############################### Graphics ##############################
|
||||
|
||||
noinst_LIBRARIES += liblyxgraphics.a
|
||||
|
Loading…
Reference in New Issue
Block a user