]> git.lyx.org Git - lyx.git/blob - src/Compare.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / Compare.h
1 // -*- C++ -*-
2 /**
3  * \file Compare.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Vincent van Ravesteijn
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef COMPARE_H
13 #define COMPARE_H
14
15 #include <QObject>
16 #include <QThread>
17 #include <QTimer>
18 #include <QWaitCondition>
19
20
21 namespace lyx {
22
23 class Buffer;
24
25 /**
26  * The options that are used by the Comparison algorithm
27  * and are set in the GuiCompare Dialog.
28  */
29 class CompareOptions {
30 public:
31         ///
32         CompareOptions()
33                 : settings_from_new(0), author(0)
34         {}
35
36         /// Copy the settings from the new or old document
37         bool settings_from_new;
38         /// Author id for change tracking
39         bool author;
40 };
41
42 /**
43  * A threaded object that does the Comparison between two documents
44  * and creates a new document with the differences marked with track
45  * changes.
46  */
47 class Compare : public QThread
48 {
49         Q_OBJECT
50
51 public:
52         ///
53         Compare(Buffer const * const old_buf, Buffer const * const new_buf,
54                 Buffer * const dest_buf, CompareOptions const & options);
55
56         ///
57         ~Compare() {
58                 abort();
59         }
60
61 Q_SIGNALS:
62         /// The thread has finished due to an error.
63         void error() const;
64
65         /// The thread has finished. If the thread is cancelled
66         /// by the user \c aborted is true.
67         void finished(bool aborted) const;
68
69         /// Adds \c progress to the value of the progress bar in the dialog
70         void progress(int progress) const ;
71
72         /// Sets the maximum value of the progress bar in the dialog.
73         void progressMax(int max) const;
74
75         /// A message describing the process
76         void statusMessage(QString msg) const;
77
78 public Q_SLOTS:
79         /// Emits the status message signal
80         void doStatusMessage();
81
82 public:
83         /// \name QThread inherited methods
84         //@{
85         void run();
86         //@}
87
88         /// Aborts the thread
89         void abort();
90
91 private:
92         /// Starts the comparison algorithm
93         int doCompare();
94
95         /// The new document's buffer
96         Buffer const * const new_buffer;
97         /// The old document's buffer
98         Buffer const * const old_buffer;
99         /// The buffer with the differences marked with track changes
100         Buffer * const dest_buffer;
101
102         /// The options that are set in the GuiCompare dialog
103         CompareOptions options_;
104
105         ///
106         QWaitCondition condition_;
107
108         /// Emit a statusMessage signal from time to time
109         QTimer status_timer_;
110
111         /// Use the Pimpl idiom to hide the internals.
112         class Impl;
113         ///
114         Impl * pimpl_;
115 };
116
117
118 } // namespace lyx
119
120 #endif