Operations widget height fix and abort button feature. Successfully

tested resizing of Operations QDockWidget for multiple concurrent
operations.
actorid
graffy76 12 years ago
parent 0c8c28e10c
commit 6f89d453a5

@ -249,6 +249,7 @@ void CSMDoc::Document::abortOperation (int type)
if (type==State_Saving)
{
mSaveCount=0;
mSaveTimer.stop();
emit stateChanged (getState(), this);
}
@ -297,4 +298,4 @@ CSMTools::ReportModel *CSMDoc::Document::getReport (const CSMWorld::UniversalId&
void CSMDoc::Document::progress (int current, int max, int type)
{
emit progress (current, max, type, 1, this);
}
}

@ -1,8 +1,11 @@
#include "operation.hpp"
#include <sstream>
#include <QProgressBar>
#include <QPushButton>
#include <QVBoxLayout>
#include "../../model/doc/document.hpp"
void CSVDoc::Operation::updateLabel (int threads)
@ -28,24 +31,44 @@ void CSVDoc::Operation::updateLabel (int threads)
stream << name << " (%p%)";
}
setFormat (stream.str().c_str());
mProgressBar->setFormat (stream.str().c_str());
}
}
CSVDoc::Operation::Operation (int type) : mType (type), mStalling (false)
CSVDoc::Operation::Operation (int type, QWidget* parent) : mType (type), mStalling (false)
{
/// \todo Add a cancel button or a pop up menu with a cancel item
initWidgets();
setBarColor( type);
updateLabel();
/// \todo assign different progress bar colours to allow the user to distinguish easily between operation types
}
CSVDoc::Operation::~Operation()
{
delete mLayout;
delete mProgressBar;
delete mAbortButton;
}
void CSVDoc::Operation::initWidgets()
{
mProgressBar = new QProgressBar ();
mAbortButton = new QPushButton("Abort");
mLayout = new QHBoxLayout();
mLayout->addWidget (mProgressBar);
mLayout->addWidget (mAbortButton);
connect (mAbortButton, SIGNAL (clicked()), this, SLOT (abortOperation()));
}
void CSVDoc::Operation::setProgress (int current, int max, int threads)
{
updateLabel (threads);
setRange (0, max);
setValue (current);
mProgressBar->setRange (0, max);
mProgressBar->setValue (current);
}
int CSVDoc::Operation::getType() const
@ -64,8 +87,6 @@ void CSVDoc::Operation::setBarColor (int type)
"margin: 2px 1px 1p 2px;"
"}";
// "QProgressBar::chunk {background-color: %1;}";
QString topColor = "#F2F6F8";
QString bottomColor = "#E0EFF9";
QString midTopColor = "#D8E1E7";
@ -82,7 +103,7 @@ void CSVDoc::Operation::setBarColor (int type)
midTopColor = "#F17432";
midBottomColor = "#EA5507";
bottomColor = "#FB955E"; // red gloss #2
//break;
break;
case CSMDoc::State_Searching:
@ -90,7 +111,7 @@ void CSVDoc::Operation::setBarColor (int type)
midTopColor = "#ABD3EE";
midBottomColor = "#89C3EB";
bottomColor = "#D5EBFB"; //blue gloss #4
//break;
break;
case CSMDoc::State_Verifying:
@ -98,7 +119,7 @@ void CSVDoc::Operation::setBarColor (int type)
midTopColor = "#8EB92A";
midBottomColor = "#72AA00";
bottomColor = "#9ECB2D"; //green gloss
//break;
break;
case CSMDoc::State_Compiling:
@ -106,7 +127,7 @@ void CSVDoc::Operation::setBarColor (int type)
midTopColor = "#C19E67";
midBottomColor = "#B68D4C";
bottomColor = "#E9D4B3"; //l Brown 3D
//break;
break;
default:
@ -116,5 +137,15 @@ void CSVDoc::Operation::setBarColor (int type)
midBottomColor = "#B5C6D0"; // gray gloss for undefined ops
}
setStyleSheet(style.arg(topColor).arg(midTopColor).arg(midBottomColor).arg(bottomColor));
mProgressBar->setStyleSheet(style.arg(topColor).arg(midTopColor).arg(midBottomColor).arg(bottomColor));
}
QHBoxLayout *CSVDoc::Operation::getLayout() const
{
return mLayout;
}
void CSVDoc::Operation::abortOperation()
{
emit abortOperation (mType);
}

@ -1,16 +1,23 @@
#ifndef CSV_DOC_OPERATION_H
#define CSV_DOC_OPERATION_H
#include <QProgressBar>
#include <QObject>
class QHBoxLayout;
class QPushButton;
class QProgressBar;
namespace CSVDoc
{
class Operation : public QProgressBar
class Operation : public QObject
{
Q_OBJECT
int mType;
bool mStalling;
QProgressBar *mProgressBar;
QPushButton *mAbortButton;
QHBoxLayout *mLayout;
// not implemented
Operation (const Operation&);
@ -20,15 +27,26 @@ namespace CSVDoc
public:
Operation (int type);
Operation (int type, QWidget *parent);
~Operation();
void setProgress (int current, int max, int threads);
int getType() const;
QHBoxLayout *getLayout() const;
private:
void setBarColor (int type);
void initWidgets();
signals:
void abortOperation (int type);
private slots:
void abortOperation();
};
}

@ -1,7 +1,7 @@
#include "operations.hpp"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "operation.hpp"
@ -11,12 +11,14 @@ CSVDoc::Operations::Operations()
setFeatures (QDockWidget::NoDockWidgetFeatures);
QWidget *widget = new QWidget;
setWidget (widget);
QWidget *widgetContainer = new QWidget (this);
mLayout = new QVBoxLayout;
widget->setLayout (mLayout);
widgetContainer->setLayout (mLayout);
setWidget (widgetContainer);
setFixedHeight (widgetContainer->height());
setTitleBarWidget (new QWidget (this));
}
void CSVDoc::Operations::setProgress (int current, int max, int type, int threads)
@ -28,11 +30,18 @@ void CSVDoc::Operations::setProgress (int current, int max, int type, int thread
return;
}
Operation *operation = new Operation (type);
int oldCount = mOperations.size();
int newCount = oldCount + 1;
mLayout->addWidget (operation);
Operation *operation = new Operation (type, this);
connect (operation, SIGNAL (abortOperation (int)), this, SIGNAL (abortOperation (int)));
mLayout->addLayout (operation->getLayout());
mOperations.push_back (operation);
operation->setProgress (current, max, threads);
if ( oldCount > 0)
setFixedHeight (height()/oldCount * newCount);
}
void CSVDoc::Operations::quitOperation (int type)
@ -40,8 +49,17 @@ void CSVDoc::Operations::quitOperation (int type)
for (std::vector<Operation *>::iterator iter (mOperations.begin()); iter!=mOperations.end(); ++iter)
if ((*iter)->getType()==type)
{
int oldCount = mOperations.size();
int newCount = oldCount - 1;
mLayout->removeItem ((*iter)->getLayout());
delete *iter;
mOperations.erase (iter);
if (oldCount > 1)
setFixedHeight (height() / oldCount * newCount);
break;
}
}
}

@ -31,7 +31,11 @@ namespace CSVDoc
void quitOperation (int type);
///< Calling this function for an operation that is not running is a no-op.
signals:
void abortOperation (int type);
};
}
#endif
#endif

@ -1,4 +1,3 @@
#include "subview.hpp"
CSVDoc::SubView::SubView (const CSMWorld::UniversalId& id) : mUniversalId (id)

@ -1,4 +1,3 @@
#include "view.hpp"
#include <sstream>
@ -7,6 +6,7 @@
#include <QCloseEvent>
#include <QMenuBar>
#include <QMdiArea>
#include <QDockWidget>
#include "../../model/doc/document.hpp"
@ -117,13 +117,16 @@ void CSVDoc::View::updateActions()
mVerify->setEnabled (!(mDocument->getState() & CSMDoc::State_Verifying));
}
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews, QMainWindow *viewParent)
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews), QMainWindow (viewParent)
{
setDockOptions (QMainWindow::AllowNestedDocks);
resize (300, 300); /// \todo get default size from settings and set reasonable minimal size
mSubViewWindow = new QMainWindow();
setCentralWidget (mSubViewWindow);
mOperations = new Operations;
addDockWidget (Qt::BottomDockWidgetArea, mOperations);
@ -133,6 +136,8 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
CSVWorld::addSubViewFactories (mSubViewFactory);
CSVTools::addSubViewFactories (mSubViewFactory);
connect (mOperations, SIGNAL (abortOperation (int)), this, SLOT (abortOperation (int)));
}
CSVDoc::View::~View()
@ -171,7 +176,7 @@ void CSVDoc::View::updateDocumentState()
for (int i=0; operations[i]!=-1; ++i)
if (!(state & operations[i]))
mOperations->quitOperation (operations[i]);
mOperations->quitOperation (operations[i]);
QList<CSVDoc::SubView *> subViews = findChildren<CSVDoc::SubView *>();
@ -195,7 +200,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id)
/// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis)
SubView *view = mSubViewFactory.makeSubView (id, *mDocument);
addDockWidget (Qt::TopDockWidgetArea, view);
mSubViewWindow->addDockWidget (Qt::TopDockWidgetArea, view);
connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this,
SLOT (addSubView (const CSMWorld::UniversalId&)));
@ -226,4 +231,16 @@ void CSVDoc::View::addGlobalsSubView()
void CSVDoc::View::addGmstsSubView()
{
addSubView (CSMWorld::UniversalId::Type_Gmsts);
}
}
void CSVDoc::View::abortOperation (int type)
{
mDocument->abortOperation (type);
mOperations->quitOperation (type);
updateActions();
}
QDockWidget *CSVDoc::View::getOperations() const
{
return mOperations;
}

@ -9,6 +9,7 @@
#include "subviewfactory.hpp"
class QAction;
class QDockWidget;
namespace CSMDoc
{
@ -40,6 +41,7 @@ namespace CSVDoc
std::vector<QAction *> mEditingActions;
Operations *mOperations;
SubViewFactoryManager mSubViewFactory;
QMainWindow* mSubViewWindow;
// not implemented
View (const View&);
@ -65,7 +67,7 @@ namespace CSVDoc
public:
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews, QMainWindow *viewParent);
///< The ownership of \a document is not transferred to *this.
virtual ~View();
@ -80,6 +82,8 @@ namespace CSVDoc
void updateProgress (int current, int max, int type, int threads);
QDockWidget *getOperations() const;
signals:
void newDocumentRequest();
@ -101,7 +105,9 @@ namespace CSVDoc
void addGlobalsSubView();
void addGmstsSubView();
void abortOperation (int type);
};
}
#endif
#endif

@ -59,7 +59,9 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
this, SLOT (progress (int, int, int, int, CSMDoc::Document *)));
}
View *view = new View (*this, document, countViews (document)+1);
QMainWindow *mainWindow = new QMainWindow;
View *view = new View (*this, document, countViews (document)+1, mainWindow);
mViews.push_back (view);
@ -119,4 +121,4 @@ void CSVDoc::ViewManager::progress (int current, int max, int type, int threads,
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
if ((*iter)->getDocument()==document)
(*iter)->updateProgress (current, max, type, threads);
}
}

Loading…
Cancel
Save