Compare: Add a statusbar to the dialog and show a message every second. The message now shows at which recursion level the algorithm is and which D-path it is currently processing.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33018 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-01-14 00:41:47 +00:00
parent 7c083bae07
commit d378b5d8ee
5 changed files with 259 additions and 184 deletions

View File

@ -18,6 +18,7 @@
#include "insets/InsetText.h" #include "insets/InsetText.h"
#include "support/lassert.h" #include "support/lassert.h"
#include "support/qstring_helpers.h"
#include <boost/next_prior.hpp> #include <boost/next_prior.hpp>
@ -219,7 +220,7 @@ class Compare::Impl {
public: public:
/// ///
Impl(Compare const & compare) Impl(Compare const & compare)
: abort_(false), compare_(compare) : abort_(false), compare_(compare), recursion_level_(0), D_(0)
{} {}
/// ///
@ -234,6 +235,14 @@ public:
/// Set to true to cancel the algorithm /// Set to true to cancel the algorithm
bool abort_; bool abort_;
///
QString status() {
QString status;
status += toqstr("recursion level:") + " " + QString::number(recursion_level_)
+ " " + toqstr("differences:") + " " + QString::number(D_);
return status;
}
private: private:
/// Finds the middle snake and returns the length of the /// Finds the middle snake and returns the length of the
/// shortest edit script. /// shortest edit script.
@ -322,6 +331,10 @@ private:
compl_vector<DocIterator> nrp; compl_vector<DocIterator> nrp;
compl_vector<DocIterator> ors; compl_vector<DocIterator> ors;
compl_vector<DocIterator> nrs; compl_vector<DocIterator> nrs;
/// The number of differences in the path the algorithm
/// is currently processing.
int D_;
}; };
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
@ -335,6 +348,15 @@ Compare::Compare(Buffer const * new_buf, Buffer const * old_buf,
: new_buffer(new_buf), old_buffer(old_buf), dest_buffer(dest_buf), : new_buffer(new_buf), old_buffer(old_buf), dest_buffer(dest_buf),
options_(options), pimpl_(new Impl(*this)) options_(options), pimpl_(new Impl(*this))
{ {
connect(&status_timer_, SIGNAL(timeout()),
this, SLOT(doStatusMessage()));
status_timer_.start(1000);
}
void Compare::doStatusMessage()
{
statusMessage(pimpl_->status());
} }
@ -347,6 +369,8 @@ void Compare::run()
dest_buffer->params() = options_.settings_from_new dest_buffer->params() = options_.settings_from_new
? new_buffer->params() : old_buffer->params(); ? new_buffer->params() : old_buffer->params();
doStatusMessage();
// do the real work // do the real work
if (!doCompare()) if (!doCompare())
return; return;
@ -605,6 +629,8 @@ int Compare::Impl::findMiddleSnake(DocRangePair const & rp,
// different characters in the old and new chunk. // different characters in the old and new chunk.
int const D_max = ceil(((double)M_ + N_)/2); int const D_max = ceil(((double)M_ + N_)/2);
for (int D = 0; D <= D_max; ++D) { for (int D = 0; D <= D_max; ++D) {
// to be used in the status messages
D_ = D;
// Forward and reverse paths // Forward and reverse paths
for (int f = 0; f < 2; ++f) { for (int f = 0; f < 2; ++f) {

View File

@ -18,6 +18,7 @@
#include <QObject> #include <QObject>
#include <QThread> #include <QThread>
#include <QTimer>
#include <QWaitCondition> #include <QWaitCondition>
#include <string> #include <string>
@ -73,6 +74,13 @@ Q_SIGNALS:
/// Sets the maximum value of the progress bar in the dialog. /// Sets the maximum value of the progress bar in the dialog.
void progressMax(int max) const; void progressMax(int max) const;
/// A message describing the process
void statusMessage(QString msg) const;
public Q_SLOTS:
/// Emits the status message signal
void doStatusMessage();
public: public:
/// QThread inherited methods /// QThread inherited methods
//@{ //@{
@ -99,6 +107,9 @@ private:
/// ///
QWaitCondition condition_; QWaitCondition condition_;
/// Emit a statusMessage signal from time to time
QTimer status_timer_;
/// Use the Pimpl idiom to hide the internals. /// Use the Pimpl idiom to hide the internals.
class Impl; class Impl;
/// ///

View File

@ -106,6 +106,7 @@ void GuiCompare::updateContents()
newFileCB->clear(); newFileCB->clear();
oldFileCB->clear(); oldFileCB->clear();
progressBar->setValue(0); progressBar->setValue(0);
statusBar->clearMessage();
BufferList::iterator it = theBufferList().begin(); BufferList::iterator it = theBufferList().begin();
BufferList::iterator const end = theBufferList().end(); BufferList::iterator const end = theBufferList().end();
for (; it != end; ++it) { for (; it != end; ++it) {
@ -211,6 +212,7 @@ void GuiCompare::finished(bool aborted)
} }
setWindowTitle(window_title_); setWindowTitle(window_title_);
progressBar->setValue(0); progressBar->setValue(0);
statusBar->showMessage(qt_("Aborted"));
} else { } else {
hideView(); hideView();
bc().ok(); bc().ok();
@ -218,6 +220,7 @@ void GuiCompare::finished(bool aborted)
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
dest_buffer_->absFileName())); dest_buffer_->absFileName()));
} }
statusBar->showMessage(qt_("Finished"));
} }
} }
@ -234,6 +237,13 @@ void GuiCompare::progressMax(int max) const
} }
void GuiCompare::setStatusMessage(QString msg)
{
statusBar->showMessage(msg);
}
void GuiCompare::slotOK() void GuiCompare::slotOK()
{ {
enableControls(false); enableControls(false);
@ -247,10 +257,12 @@ void GuiCompare::slotCancel()
if (compare_ && compare_->isRunning()) { if (compare_ && compare_->isRunning()) {
window_title_ = windowTitle(); window_title_ = windowTitle();
setWindowTitle(window_title_ + " " + qt_("(cancelling)")); setWindowTitle(window_title_ + " " + qt_("(cancelling)"));
statusBar->showMessage(qt_("Aborting process..."));
compare_->abort(); compare_->abort();
} else { } else {
GuiDialog::slotClose(); GuiDialog::slotClose();
progressBar->setValue(0); progressBar->setValue(0);
statusBar->clearMessage();
} }
} }
@ -299,6 +311,8 @@ int GuiCompare::run()
connect(compare_, SIGNAL(finished(bool)), this, SLOT(finished(bool))); connect(compare_, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
connect(compare_, SIGNAL(progress(int)), this, SLOT(progress(int))); connect(compare_, SIGNAL(progress(int)), this, SLOT(progress(int)));
connect(compare_, SIGNAL(progressMax(int)), this, SLOT(progressMax(int))); connect(compare_, SIGNAL(progressMax(int)), this, SLOT(progressMax(int)));
connect(compare_, SIGNAL(statusMessage(QString)),
this, SLOT(setStatusMessage(QString)));
compare_->start(QThread::LowPriority); compare_->start(QThread::LowPriority);
return 1; return 1;
} }

View File

@ -53,6 +53,8 @@ private Q_SLOTS:
void progress(int); void progress(int);
/// ///
void progressMax(int) const; void progressMax(int) const;
///
void setStatusMessage(QString);
private: private:
/// ///

View File

@ -1,7 +1,7 @@
<ui version="4.0" > <ui version="4.0">
<class>CompareUi</class> <class>CompareUi</class>
<widget class="QDialog" name="CompareUi" > <widget class="QDialog" name="CompareUi">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,211 +9,233 @@
<height>302</height> <height>302</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string/> <string/>
</property> </property>
<property name="sizeGripEnabled" > <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2" > <layout class="QVBoxLayout" name="verticalLayout_1">
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="newFileLA" > <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="text" > <property name="leftMargin">
<string>&amp;New Document:</string> <number>9</number>
</property> </property>
<property name="buddy" > <property name="topMargin">
<cstring>newFileCB</cstring> <number>9</number>
</property> </property>
</widget> <property name="rightMargin">
</item> <number>9</number>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QComboBox" name="newFileCB" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newFilePB" >
<property name="text" >
<string>&amp;Browse...</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="oldFileLA" >
<property name="text" >
<string>&amp;Old Document:</string>
</property> </property>
<property name="buddy" > <property name="bottomMargin">
<cstring>oldFileCB</cstring>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QComboBox" name="oldFileCB" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="oldFilePB" >
<property name="text" >
<string>Bro&amp;wse...</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title" >
<string>Options</string>
</property>
<widget class="QRadioButton" name="newSettingsRB" >
<property name="geometry" >
<rect>
<x>20</x>
<y>40</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>New Document</string>
</property>
</widget>
<widget class="QRadioButton" name="oldSettingsRB" >
<property name="geometry" >
<rect>
<x>20</x>
<y>60</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>Old Document</string>
</property>
</widget>
<widget class="QLabel" name="label" >
<property name="geometry" >
<rect>
<x>20</x>
<y>20</y>
<width>237</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Copy Document Settings from:</string>
</property>
<property name="scaledContents" >
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar" >
<property name="value" >
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<spacer> <widget class="QLabel" name="newFileLA">
<property name="orientation" > <property name="text">
<enum>Qt::Horizontal</enum> <string>&amp;New Document:</string>
</property> </property>
<property name="sizeType" > <property name="buddy">
<enum>QSizePolicy::Expanding</enum> <cstring>newFileCB</cstring>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="closePB" > <layout class="QHBoxLayout" name="horizontalLayout">
<property name="text" > <item>
<string>&amp;Close</string> <widget class="QComboBox" name="newFileCB">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newFilePB">
<property name="text">
<string>&amp;Browse...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="oldFileLA">
<property name="text">
<string>&amp;Old Document:</string>
</property> </property>
<property name="autoDefault" > <property name="buddy">
<bool>false</bool> <cstring>oldFileCB</cstring>
</property>
<property name="default" >
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="oldFileCB">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="oldFilePB">
<property name="text">
<string>Bro&amp;wse...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Options</string>
</property>
<widget class="QRadioButton" name="newSettingsRB">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>New Document</string>
</property>
</widget>
<widget class="QRadioButton" name="oldSettingsRB">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Old Document</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>237</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Copy Document Settings from:</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item>
<widget class="QStatusBar" name="statusBar"/>
</item>
</layout> </layout>
</widget> </widget>
<includes> <includes>
<include location="local" >qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>