source: src/UIElements/Views/Qt4/QtStatusBar.cpp@ 34e7fdb

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 34e7fdb was 378f2d5, checked in by Frederik Heber <heber@…>, 11 years ago

Updated all UI's StatusIndicator classes to use ActionStatusList.

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]21 */
22
[b47bfc]23/*
[4cf323d]24 * QtStatusBar.cpp
[b47bfc]25 *
26 * Created on: Feb 17, 2010
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
[bbbad5]34
[b47bfc]35#include <sstream>
36
37#include <QtGui/QLabel>
38#include <QtGui/QBoxLayout>
[426c84]39#include <QtCore/QMetaType>
[b47bfc]40#include <QtGui/QProgressBar>
[378f2d5]41#include <QtCore/QTimer>
[b47bfc]42
[4cf323d]43#include "QtStatusBar.hpp"
[bbbad5]44
[ad011c]45#include "CodePatterns/MemDebug.hpp"
[378f2d5]46#include "CodePatterns/Observer/Notification.hpp"
[bbbad5]47
[b47bfc]48#include "World.hpp"
[378f2d5]49#include "Actions/ActionQueue.hpp"
50#include "Actions/ActionStatusList.hpp"
[b47bfc]51#include "Actions/Process.hpp"
52
[5605793]53#define PLURAL_S(v) (((v)==1)?"":"s")
54
[ce7fdc]55using namespace MoleCuilder;
[b47bfc]56
[4cf323d]57QtStatusBar::QtStatusBar(QWidget *_parent) :
[b47bfc]58 QStatusBar(_parent),
[4cf323d]59 Observer("QtStatusBar"),
[b47bfc]60 atomCount(World::getInstance().numAtoms()),
[fc7504]61 moleculeCount(World::getInstance().numMolecules()),
[426c84]62 parent(_parent),
[378f2d5]63 activeProcess(""),
64 StatusList(ActionQueue::getInstance().getStatusList()),
65 StatusList_signedOn(false),
66 timer(NULL),
67 timer_interval(1500)
[b47bfc]68{
69 World::getInstance().signOn(this);
70 Process::AddObserver(this);
[378f2d5]71 StatusList.signOn(this, ActionStatusList::StatusAdded);
72 StatusList_signedOn = true;
[b47bfc]73 statusLabel = new QLabel(this);
74 statusLabel->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
75 addPermanentWidget(statusLabel);
76 redrawStatus();
[426c84]77
[378f2d5]78 // connect the timer
79 timer = new QTimer(this);
80 timer->stop();
81 connect(timer, SIGNAL(timeout()), this, SLOT(updateStatusMessage()));
82
[426c84]83 qRegisterMetaType<std::string>("std::string");
84 connect(
85 this, SIGNAL(redrawProgressBar(const std::string, const unsigned int, const unsigned int, const bool)),
86 this, SLOT(updateProgressBar(const std::string, const unsigned int, const unsigned int, const bool)));
[b47bfc]87}
88
[4cf323d]89QtStatusBar::~QtStatusBar()
[b47bfc]90{
[378f2d5]91 // stop the timer if it is running
92 if (timer->isActive())
93 timer->stop();
94
[b47bfc]95 Process::RemoveObserver(this);
96 World::getInstance().signOff(this);
[378f2d5]97 if (StatusList_signedOn)
98 StatusList.signOff(this, ActionStatusList::StatusAdded);
[b47bfc]99}
100
[4cf323d]101void QtStatusBar::update(Observable *subject){
[378f2d5]102 if (subject == World::getPointer()){
[b47bfc]103 atomCount = World::getInstance().numAtoms();
104 moleculeCount = World::getInstance().numMolecules();
[378f2d5]105 // redraw only if no timer updates messages
106 if (!timer->isActive())
107 redrawStatus();
108 } else if (subject == &StatusList) {
109 // we do not react to general updates from StatusList
110 } else {
[b47bfc]111 // we probably have some process
[426c84]112 // as notify comes from ActionQueue's thread, we have to use signal/slots
113 // to inform ourselves but within the main() thread to be able to add
114 // the progressbar widget.
[b47bfc]115 Process *proc;
116 if((proc=dynamic_cast<Process*>(subject))){
[426c84]117 const bool StopStatus = proc->doesStop();
118 emit redrawProgressBar(proc->getName(), proc->getMaxSteps(), proc->getCurrStep(), StopStatus);
[b47bfc]119 }
120 }
121}
122
[378f2d5]123void QtStatusBar::startTimer()
124{
125 timer->start(timer_interval);
126}
127
128void QtStatusBar::stopTimer()
129{
130 timer->stop();
131}
132
133void QtStatusBar::updateStatusMessage()
134{
135 if (StatusList.size() != 0) {
136 // get oldest message from the StatusList
137 const std::string message = StatusList.popFirstMessage();
138 statusLabel->setText(QString(message.c_str()));
139 } else {
140 // just send the standard message
141 redrawStatus();
142 // and stop the timer
143 stopTimer();
144 }
145}
146
147void QtStatusBar::recieveNotification(Observable *_publisher, Notification *_notification)
148{
149 if (_publisher == &StatusList) {
150 switch(_notification->getChannelNo()) {
151 case MoleCuilder::ActionStatusList::StatusAdded:
152 if (!timer->isActive()) {
153 // if timer is not already running
154 updateStatusMessage();
155 startTimer();
156 }
157 break;
158 }
159 }
160}
161
162void QtStatusBar::subjectKilled(Observable *subject)
163{
[b47bfc]164 // Processes don't notify when they are killed
[378f2d5]165 if (subject == &StatusList) {
166 // print all remaining messages
167 while (StatusList.size() != 0)
168 updateStatusMessage();
169 // don't need to sign off, just note down that we are
170 StatusList_signedOn = false;
171 } else {
172 atomCount = World::getInstance().numAtoms();
173 moleculeCount = World::getInstance().numMolecules();
174 World::getInstance().signOn(this);
175 redrawStatus();
176 }
[b47bfc]177}
178
[4cf323d]179void QtStatusBar::redrawStatus(){
[b47bfc]180 stringstream sstr;
181 sstr << "You have " << atomCount << " atom" << PLURAL_S(atomCount)
182 <<" in " << moleculeCount << " molecule" << PLURAL_S(moleculeCount);
183 statusLabel->setText(QString(sstr.str().c_str()));
184}
185
[426c84]186void QtStatusBar::updateProgressBar(
187 const std::string name,
188 const unsigned int maxsteps,
189 const unsigned int currentstep,
190 const bool StopStatus)
191{
[b47bfc]192 progressIndicator *ind=0;
[426c84]193 progressBars_t::iterator iter = progressBars.find(name);
[b47bfc]194 // see what we have to do with the process
[426c84]195 if (iter == progressBars.end()) {
196 ind = new progressIndicator(name);
197 ind->bar->setMaximum(maxsteps);
198 progressBars.insert( std::make_pair(name,ind) );
199 } else {
200 ind = iter->second;
[b47bfc]201 }
[426c84]202 if (activeProcess != name) {
[b47bfc]203 addWidget(ind->container);
[426c84]204 activeProcess = name;
[b47bfc]205 }
[426c84]206 ind->bar->setValue(currentstep);
[b47bfc]207 parent->repaint();
[426c84]208 if ((iter != progressBars.end()) && StopStatus) {
[b47bfc]209 removeWidget(ind->container);
[426c84]210 activeProcess = std::string("");
211 progressBars.erase(name);
[b47bfc]212 delete ind;
213 }
214}
215
216
217
[426c84]218QtStatusBar::progressIndicator::progressIndicator(const std::string &name){
[b47bfc]219 stringstream sstr;
220 sstr << "Busy (" << name << ")";
221 container = new QWidget();
222 layout = new QHBoxLayout(container);
223 label = new QLabel(QString(sstr.str().c_str()));
224 bar = new QProgressBar();
225
226 layout->addWidget(label);
227 layout->addWidget(bar);
228 container->setLayout(layout);
229}
230
[4cf323d]231QtStatusBar::progressIndicator::~progressIndicator(){
[b47bfc]232 delete container;
233}
Note: See TracBrowser for help on using the repository browser.