comparison view/View.cpp @ 555:3f698e237585

* Pop view progress bars back into "indeterminate" mode if they are not updated for a couple of seconds (useful for plugins with very active getRemainingFeatures())
author Chris Cannam
date Fri, 12 Mar 2010 15:34:18 +0000
parents 265898470c53
children 95cf0d0f93af
comparison
equal deleted inserted replaced
554:ffeafe09c8d9 555:3f698e237585
529 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer); 529 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer);
530 if (scl) scl->setDefaultColourFor(this); 530 if (scl) scl->setDefaultColourFor(this);
531 531
532 m_layers.push_back(layer); 532 m_layers.push_back(layer);
533 533
534 // m_progressBars[layer] = new LayerProgressBar(this); 534 QProgressBar *pb = new QProgressBar(this);
535 m_progressBars[layer] = new QProgressBar(this); 535 pb->setMinimum(0);
536 m_progressBars[layer]->setMinimum(0); 536 pb->setMaximum(0);
537 m_progressBars[layer]->setMaximum(0); 537 pb->setFixedWidth(80);
538 // m_progressBars[layer]->setMaximum(100); 538 pb->setTextVisible(false);
539 // m_progressBars[layer]->setMinimumWidth(80); 539
540 m_progressBars[layer]->setFixedWidth(80); 540 ProgressBarRec pbr;
541 // m_progressBars[layer]->setText(""); //!!! 541 pbr.bar = pb;
542 m_progressBars[layer]->setTextVisible(false); 542 pbr.lastCheck = 0;
543 543 pbr.checkTimer = new QTimer();
544 QFont f(m_progressBars[layer]->font()); 544 connect(pbr.checkTimer, SIGNAL(timeout()), this,
545 SLOT(progressCheckStalledTimerElapsed()));
546
547 m_progressBars[layer] = pbr;
548
549 QFont f(pb->font());
545 int fs = Preferences::getInstance()->getViewFontSize(); 550 int fs = Preferences::getInstance()->getViewFontSize();
546 f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); 551 f.setPointSize(std::min(fs, int(ceil(fs * 0.85))));
547 552
548 m_progressBars[layer]->setFont(f); 553 pb->setFont(f);
549 m_progressBars[layer]->hide(); 554 pb->hide();
550 555
551 connect(layer, SIGNAL(layerParametersChanged()), 556 connect(layer, SIGNAL(layerParametersChanged()),
552 this, SLOT(layerParametersChanged())); 557 this, SLOT(layerParametersChanged()));
553 connect(layer, SIGNAL(layerParameterRangesChanged()), 558 connect(layer, SIGNAL(layerParameterRangesChanged()),
554 this, SLOT(layerParameterRangesChanged())); 559 this, SLOT(layerParameterRangesChanged()));
584 589
585 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 590 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
586 if (*i == layer) { 591 if (*i == layer) {
587 m_layers.erase(i); 592 m_layers.erase(i);
588 if (m_progressBars.find(layer) != m_progressBars.end()) { 593 if (m_progressBars.find(layer) != m_progressBars.end()) {
589 delete m_progressBars[layer]; 594 delete m_progressBars[layer].bar;
595 delete m_progressBars[layer].checkTimer;
590 m_progressBars.erase(layer); 596 m_progressBars.erase(layer);
591 } 597 }
592 break; 598 break;
593 } 599 }
594 } 600 }
1404 { 1410 {
1405 if (!m_showProgress) return; 1411 if (!m_showProgress) return;
1406 1412
1407 int ph = height(); 1413 int ph = height();
1408 1414
1409 for (ProgressMap::const_iterator i = m_progressBars.begin(); 1415 for (ProgressMap::iterator i = m_progressBars.begin();
1410 i != m_progressBars.end(); ++i) { 1416 i != m_progressBars.end(); ++i) {
1411 1417
1418 QProgressBar *pb = i->second.bar;
1419
1412 if (i->first == object) { 1420 if (i->first == object) {
1421
1422 // The timer is used to test for stalls. If the progress
1423 // bar does not get updated for some length of time, the
1424 // timer prompts it to go back into "indeterminate" mode
1425 QTimer *timer = i->second.checkTimer;
1413 1426
1414 int completion = i->first->getCompletion(this); 1427 int completion = i->first->getCompletion(this);
1415 QString text = i->first->getPropertyContainerName(); 1428 QString text = i->first->getPropertyContainerName();
1416 1429
1417 Model *model = i->first->getModel(); 1430 Model *model = i->first->getModel();
1418 RangeSummarisableTimeValueModel *wfm = 1431 RangeSummarisableTimeValueModel *wfm =
1419 dynamic_cast<RangeSummarisableTimeValueModel *>(model); 1432 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
1420 1433
1421 if (completion > 0) { 1434 if (completion > 0) {
1422 i->second->setMaximum(100); // was 0, for indeterminate start 1435 pb->setMaximum(100); // was 0, for indeterminate start
1423 } 1436 }
1424 1437
1425 if (completion >= 100) { 1438 if (completion >= 100) {
1426 1439
1427 //!!! 1440 //!!!
1439 update(); // ensure duration &c gets updated 1452 update(); // ensure duration &c gets updated
1440 } 1453 }
1441 1454
1442 if (completion >= 100) { 1455 if (completion >= 100) {
1443 1456
1444 i->second->hide(); 1457 pb->hide();
1458 timer->stop();
1445 1459
1446 } else { 1460 } else {
1447 1461
1448 // i->second->setText(text); 1462 // std::cerr << "progress = " << completion << std::endl;
1449 1463
1450 i->second->setValue(completion); 1464 if (!pb->isVisible()) {
1451 i->second->move(0, ph - i->second->height()); 1465 i->second.lastCheck = 0;
1452 1466 timer->setInterval(2000);
1453 i->second->show(); 1467 timer->start();
1454 i->second->update(); 1468 }
1455 1469
1456 ph -= i->second->height(); 1470 pb->setValue(completion);
1471 pb->move(0, ph - pb->height());
1472
1473 pb->show();
1474 pb->update();
1475
1476 ph -= pb->height();
1457 } 1477 }
1458 } else { 1478 } else {
1459 if (i->second->isVisible()) { 1479 if (pb->isVisible()) {
1460 ph -= i->second->height(); 1480 ph -= pb->height();
1461 } 1481 }
1462 } 1482 }
1483 }
1484 }
1485
1486 void
1487 View::progressCheckStalledTimerElapsed()
1488 {
1489 QObject *s = sender();
1490 QTimer *t = qobject_cast<QTimer *>(s);
1491 if (!t) return;
1492 for (ProgressMap::iterator i = m_progressBars.begin();
1493 i != m_progressBars.end(); ++i) {
1494 if (i->second.checkTimer == t) {
1495 int value = i->second.bar->value();
1496 if (value > 0 && value == i->second.lastCheck) {
1497 i->second.bar->setMaximum(0); // indeterminate
1498 }
1499 i->second.lastCheck = value;
1500 return;
1501 }
1463 } 1502 }
1464 } 1503 }
1465 1504
1466 int 1505 int
1467 View::getProgressBarWidth() const 1506 View::getProgressBarWidth() const
1468 { 1507 {
1469 for (ProgressMap::const_iterator i = m_progressBars.begin(); 1508 for (ProgressMap::const_iterator i = m_progressBars.begin();
1470 i != m_progressBars.end(); ++i) { 1509 i != m_progressBars.end(); ++i) {
1471 if (i->second && i->second->isVisible()) return i->second->width(); 1510 if (i->second.bar && i->second.bar->isVisible()) {
1511 return i->second.bar->width();
1512 }
1472 } 1513 }
1473 1514
1474 return 0; 1515 return 0;
1475 } 1516 }
1476 1517