[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Public Slots | Public Member Functions | Protected Member Functions
KLFProgressDialog Class Reference

A Progress Dialog. More...

#include <klfguiutil.h>

List of all members.

Public Slots

virtual void setDescriptiveText (const QString &labelText)
virtual void startReportingProgress (KLFProgressReporter *progressReporter, const QString &descriptiveText)
virtual void startReportingProgress (KLFProgressReporter *progressReporter)
virtual void setValue (int value)

Public Member Functions

 KLFProgressDialog (QString labelText=QString(), QWidget *parent=NULL)
 KLFProgressDialog (bool canCancel, QString labelText, QWidget *parent)
virtual ~KLFProgressDialog ()

Protected Member Functions

void paintEvent (QPaintEvent *event)

Detailed Description

A Progress Dialog.

This class is a QProgressDialog derivative that is optimized to work for klatexformula's needs, especially making it easy to use with KLFProgressReporter.

Among others, this dialog provides a straightforward option to disable the Cancel button.

Basically this is just a wrapper around QProgressDialog's functions. Typical use is:

  MyWidget::someLengthyOperation()
  {
    int number_of_steps = ...;
    KLFProgressDialog pdlg(false, this); // disable cancel
    KLFProgressReporter progressReporter(0, number_of_steps);
    pdlg.startReportingProgress(&progressReporter, "Please wait until some long operation completes...");
    ...
    int step = 0;
    for (step = 0; step < number_of_steps; ++step) {
      // an iteration step
      ...
      progressReporter.doReportProgress(step)
    }
  }

The previous example is somewhat trivial and does not exhibit the advantages of the features of this class and of KLFProgressReporter over QProgressDialog; the example of KLFLibResourceEngine is more relevant:

 // klflib.h  : the library resource engine system (no GUI)
 class KLFLibResourceEngine {
    ....
 signals:
   void operationStartReportingProgress(KLFProgressReporter *progressReporter, const QString& label);

   ...
 };

 // klflibbrowser.cpp  : the library browser (GUI)
   ...
 bool KLFLibBrowser::openResource(...)
 {
   ...
   connect(resource, SIGNAL(operationStartReportingProgress(KLFProgressReporter *, const QString&)),
          this, SLOT(slotStartProgress(KLFProgressReporter *, const QString&)));
   ...
 }
 void KLFLibBrowser::slotStartProgress(KLFProgressReporter *progressReporter, const QString& label)
 {
   KLFProgressDialog *pdialog = new KLFProgressDialog(false, QString(), this);
   pdialog->startReportingProgress(progressReporter, label);
   ...
 }

which opens a progress dialog whenever the resource emits an operationStartReportingProgress() signal. Note that in this example, we have not provided the means to delete the progress dialog once it has completed; for details have a look at the source code of klflibbrowser.cpp.

For yet another example of inline (on-the-stack) usage of KLFProgressDialog, check out KLFLibBrowser::slotExport() in klflibbrowser.cpp.

Todo:
.... I'm not sure, but to delete the dialog, couldn't we simply connect KLFProgressReporter::finished() to KLFProgressDialog::deleteLater() ... ? needs a test.

Definition at line 172 of file klfguiutil.h.


Constructor & Destructor Documentation

KLFProgressDialog::KLFProgressDialog ( QString  labelText = QString(),
QWidget *  parent = NULL 
)

Build a progress dialog with the given labelText and parent

Definition at line 74 of file klfguiutil.cpp.

KLFProgressDialog::KLFProgressDialog ( bool  canCancel,
QString  labelText,
QWidget *  parent 
)

Build a progress dialog with a cancel button that is enabled or disabled (following the value of canCancel), with label labelText, and parent parent.

Definition at line 80 of file klfguiutil.cpp.

Definition at line 86 of file klfguiutil.cpp.


Member Function Documentation

void KLFProgressDialog::paintEvent ( QPaintEvent event) [protected]

Definition at line 147 of file klfguiutil.cpp.

References KLF_DEBUG_BLOCK, and KLF_FUNC_NAME.

void KLFProgressDialog::setDescriptiveText ( const QString labelText) [virtual, slot]

same as QProgressDialog::setLabelText() but resizes the dialog a bit larger so that its looks nicer.

Definition at line 108 of file klfguiutil.cpp.

Referenced by startReportingProgress().

void KLFProgressDialog::setValue ( int  value) [virtual, slot]

Calls directly QProgressDialog::setValue()

Definition at line 140 of file klfguiutil.cpp.

References klfDbg.

Referenced by startReportingProgress().

void KLFProgressDialog::startReportingProgress ( KLFProgressReporter progressReporter,
const QString descriptiveText 
) [virtual, slot]

start reporting progress from progressReporter and set label text to descriptiveText.

Note:
This will disconnect the previously set progress reporter to the slot setValue()

Definition at line 113 of file klfguiutil.cpp.

References KLFProgressReporter::max(), KLFProgressReporter::min(), setDescriptiveText(), and setValue().

void KLFProgressDialog::startReportingProgress ( KLFProgressReporter progressReporter) [virtual, slot]

start reporting progress from progressReporter, without changing label text.

Note:
This will disconnect the previously set progress reporter to the slot setValue()

Definition at line 128 of file klfguiutil.cpp.

References KLFProgressReporter::max(), KLFProgressReporter::min(), and setValue().


The documentation for this class was generated from the following files:

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net