comparison view/View.cpp @ 1496:d09345e578a7

Separate out handling of alignment progress bar from the layer progress bars and fix tendency to have them hanging around even when alignment has completed
author Chris Cannam
date Wed, 14 Aug 2019 10:58:24 +0100
parents 6bb0afa607f5
children 60fe0d20df5d
comparison
equal deleted inserted replaced
1495:6bb0afa607f5 1496:d09345e578a7
70 m_cacheZoomLevel(ZoomLevel::FramesPerPixel, 1024), 70 m_cacheZoomLevel(ZoomLevel::FramesPerPixel, 1024),
71 m_selectionCached(false), 71 m_selectionCached(false),
72 m_deleting(false), 72 m_deleting(false),
73 m_haveSelectedLayer(false), 73 m_haveSelectedLayer(false),
74 m_useAligningProxy(false), 74 m_useAligningProxy(false),
75 m_alignmentProgressBar({ {}, nullptr }),
75 m_manager(nullptr), 76 m_manager(nullptr),
76 m_propertyContainer(new ViewPropertyContainer(this)) 77 m_propertyContainer(new ViewPropertyContainer(this))
77 { 78 {
78 // cerr << "View::View(" << getId() << ")" << endl; 79 // cerr << "View::View(" << getId() << ")" << endl;
79 } 80 }
681 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); 682 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
682 683
683 ProgressBarRec pbr; 684 ProgressBarRec pbr;
684 pbr.cancel = cancel; 685 pbr.cancel = cancel;
685 pbr.bar = pb; 686 pbr.bar = pb;
686 pbr.lastCheck = 0; 687 pbr.lastStallCheckValue = 0;
687 pbr.checkTimer = new QTimer(); 688 pbr.stallCheckTimer = new QTimer();
688 connect(pbr.checkTimer, SIGNAL(timeout()), this, 689 connect(pbr.stallCheckTimer, SIGNAL(timeout()), this,
689 SLOT(progressCheckStalledTimerElapsed())); 690 SLOT(progressCheckStalledTimerElapsed()));
690 691
691 m_progressBars[layer] = pbr; 692 m_progressBars[layer] = pbr;
692 693
693 QFont f(pb->font()); 694 QFont f(pb->font());
747 if (*i == layer) { 748 if (*i == layer) {
748 m_layerStack.erase(i); 749 m_layerStack.erase(i);
749 if (m_progressBars.find(layer) != m_progressBars.end()) { 750 if (m_progressBars.find(layer) != m_progressBars.end()) {
750 delete m_progressBars[layer].bar; 751 delete m_progressBars[layer].bar;
751 delete m_progressBars[layer].cancel; 752 delete m_progressBars[layer].cancel;
752 delete m_progressBars[layer].checkTimer; 753 delete m_progressBars[layer].stallCheckTimer;
753 m_progressBars.erase(layer); 754 m_progressBars.erase(layer);
754 } 755 }
755 break; 756 break;
756 } 757 }
757 } 758 }
1015 View::modelAlignmentCompletionChanged(ModelId modelId) 1016 View::modelAlignmentCompletionChanged(ModelId modelId)
1016 { 1017 {
1017 #ifdef DEBUG_PROGRESS_STUFF 1018 #ifdef DEBUG_PROGRESS_STUFF
1018 cerr << "View[" << getId() << "]::modelAlignmentCompletionChanged(" << modelId << ")" << endl; 1019 cerr << "View[" << getId() << "]::modelAlignmentCompletionChanged(" << modelId << ")" << endl;
1019 #endif 1020 #endif
1020 checkProgress(modelId); 1021 checkAlignmentProgress(modelId);
1021 } 1022 }
1022 1023
1023 void 1024 void
1024 View::modelReplaced() 1025 View::modelReplaced()
1025 { 1026 {
1766 << "m_showProgress is off" << endl; 1767 << "m_showProgress is off" << endl;
1767 #endif 1768 #endif
1768 return; 1769 return;
1769 } 1770 }
1770 1771
1772 #ifdef DEBUG_PROGRESS_STUFF
1773 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << ")" << endl;
1774 #endif
1775
1771 QSettings settings; 1776 QSettings settings;
1772 settings.beginGroup("View"); 1777 settings.beginGroup("View");
1773 bool showCancelButton = settings.value("showcancelbuttons", true).toBool(); 1778 bool showCancelButton = settings.value("showcancelbuttons", true).toBool();
1774 settings.endGroup(); 1779 settings.endGroup();
1775 1780
1776 int ph = height(); 1781 int ph = height();
1777 bool found = false; 1782 bool found = false;
1778 1783
1784 if (m_alignmentProgressBar.bar) {
1785 ph -= m_alignmentProgressBar.bar->height();
1786 }
1787
1779 for (ProgressMap::iterator i = m_progressBars.begin(); 1788 for (ProgressMap::iterator i = m_progressBars.begin();
1780 i != m_progressBars.end(); ++i) { 1789 i != m_progressBars.end(); ++i) {
1781 1790
1782 QProgressBar *pb = i->second.bar; 1791 QProgressBar *pb = i->second.bar;
1783 QPushButton *cancel = i->second.cancel; 1792 QPushButton *cancel = i->second.cancel;
1784 1793
1785 if (i->first && i->first->getModel() == modelId) { 1794 if (i->first && i->first->getModel() == modelId) {
1786 1795
1787 found = true; 1796 found = true;
1788 bool isAlignmentProgress = false;
1789 1797
1790 // The timer is used to test for stalls. If the progress 1798 // The timer is used to test for stalls. If the progress
1791 // bar does not get updated for some length of time, the 1799 // bar does not get updated for some length of time, the
1792 // timer prompts it to go back into "indeterminate" mode 1800 // timer prompts it to go back into "indeterminate" mode
1793 QTimer *timer = i->second.checkTimer; 1801 QTimer *timer = i->second.stallCheckTimer;
1794 1802
1795 int completion = i->first->getCompletion(this); 1803 int completion = i->first->getCompletion(this);
1796 QString text = i->first->getPropertyContainerName();
1797 QString error = i->first->getError(this); 1804 QString error = i->first->getError(this);
1798 1805
1799 #ifdef DEBUG_PROGRESS_STUFF 1806 #ifdef DEBUG_PROGRESS_STUFF
1800 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): " 1807 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
1801 << "found progress bar " << pb << " for layer at height " << ph 1808 << "found progress bar " << pb << " for layer at height " << ph
1805 if (error != "" && error != m_lastError) { 1812 if (error != "" && error != m_lastError) {
1806 QMessageBox::critical(this, tr("Layer rendering error"), error); 1813 QMessageBox::critical(this, tr("Layer rendering error"), error);
1807 m_lastError = error; 1814 m_lastError = error;
1808 } 1815 }
1809 1816
1810 auto model = ModelById::get(modelId);
1811 auto wfm = std::dynamic_pointer_cast
1812 <RangeSummarisableTimeValueModel>(model);
1813
1814 if (completion > 0) { 1817 if (completion > 0) {
1815 pb->setMaximum(100); // was 0, for indeterminate start 1818 pb->setMaximum(100); // was 0, for indeterminate start
1816 } 1819 }
1817 1820
1818 if (completion >= 100) { 1821 if (completion < 100 &&
1819 1822 ModelById::isa<RangeSummarisableTimeValueModel>(modelId)) {
1820 if (wfm ||
1821 (model &&
1822 (wfm = ModelById::getAs<RangeSummarisableTimeValueModel>
1823 (model->getSourceModel())))) {
1824
1825 isAlignmentProgress = true;
1826
1827 completion = wfm->getAlignmentCompletion();
1828
1829 // We don't allow cancelling alignment operations
1830 // - they aren't usually all that expensive, and
1831 // it would leave things in a very uncertain state
1832 showCancelButton = false;
1833
1834 #ifdef DEBUG_PROGRESS_STUFF
1835 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
1836 << "alignment completion = " << completion << endl;
1837 #endif
1838
1839 if (completion < 100) {
1840 text = tr("Alignment");
1841 }
1842 }
1843
1844 } else if (wfm) {
1845 update(); // ensure duration &c gets updated 1823 update(); // ensure duration &c gets updated
1846 } 1824 }
1847 1825
1848 if (completion >= 100) { 1826 if (completion >= 100) {
1849 1827
1850 pb->hide(); 1828 pb->hide();
1851 cancel->hide(); 1829 cancel->hide();
1852 timer->stop(); 1830 timer->stop();
1853 1831
1854 } else if (i->first->isLayerDormant(this) && !isAlignmentProgress) { 1832 } else if (i->first->isLayerDormant(this)) {
1855 1833
1856 // A dormant (invisible) layer can still be busy 1834 // A dormant (invisible) layer can still be busy
1857 // generating, but we don't usually want to indicate 1835 // generating, but we don't usually want to indicate
1858 // it because it probably means it's a duplicate of a 1836 // it because it probably means it's a duplicate of a
1859 // visible layer 1837 // visible layer
1866 timer->stop(); 1844 timer->stop();
1867 1845
1868 } else { 1846 } else {
1869 1847
1870 if (!pb->isVisible()) { 1848 if (!pb->isVisible()) {
1871 i->second.lastCheck = 0; 1849 i->second.lastStallCheckValue = 0;
1872 timer->setInterval(2000); 1850 timer->setInterval(2000);
1873 timer->start(); 1851 timer->start();
1874 } 1852 }
1875 1853
1876 if (showCancelButton) { 1854 if (showCancelButton) {
1913 #endif 1891 #endif
1914 } 1892 }
1915 } 1893 }
1916 1894
1917 void 1895 void
1896 View::checkAlignmentProgress(ModelId modelId)
1897 {
1898 if (!m_showProgress) {
1899 #ifdef DEBUG_PROGRESS_STUFF
1900 SVCERR << "View[" << getId() << "]::checkAlignmentProgress(" << modelId << "): "
1901 << "m_showProgress is off" << endl;
1902 #endif
1903 return;
1904 }
1905
1906 #ifdef DEBUG_PROGRESS_STUFF
1907 SVCERR << "View[" << getId() << "]::checkAlignmentProgress(" << modelId << ")" << endl;
1908 #endif
1909
1910 if (!m_alignmentProgressBar.alignedModel.isNone() &&
1911 modelId != m_alignmentProgressBar.alignedModel) {
1912 #ifdef DEBUG_PROGRESS_STUFF
1913 SVCERR << "View[" << getId() << "]::checkAlignmentProgress(" << modelId << "): Different model (we're currently showing alignment progress for " << modelId << ", ignoring" << endl;
1914 #endif
1915 return;
1916 }
1917
1918 auto model = ModelById::get(modelId);
1919 if (!model) {
1920 #ifdef DEBUG_PROGRESS_STUFF
1921 SVCERR << "View[" << getId() << "]::checkAlignmentProgress(" << modelId << "): Model gone" << endl;
1922 #endif
1923 m_alignmentProgressBar.alignedModel = {};
1924 delete m_alignmentProgressBar.bar;
1925 m_alignmentProgressBar.bar = nullptr;
1926 return;
1927 }
1928
1929 int completion = model->getAlignmentCompletion();
1930
1931 #ifdef DEBUG_PROGRESS_STUFF
1932 SVCERR << "View[" << getId() << "]::checkAlignmentProgress(" << modelId << "): Completion is " << completion << endl;
1933 #endif
1934
1935 int ph = height();
1936
1937 if (completion >= 100) {
1938 m_alignmentProgressBar.alignedModel = {};
1939 delete m_alignmentProgressBar.bar;
1940 m_alignmentProgressBar.bar = nullptr;
1941 return;
1942 }
1943
1944 QProgressBar *pb = m_alignmentProgressBar.bar;
1945 if (!pb) {
1946 pb = new QProgressBar(this);
1947 pb->setMinimum(0);
1948 pb->setMaximum(100);
1949 pb->setFixedWidth(80);
1950 pb->setTextVisible(false);
1951 m_alignmentProgressBar.alignedModel = modelId;
1952 m_alignmentProgressBar.bar = pb;
1953 }
1954
1955 pb->setValue(completion);
1956 pb->move(0, ph - pb->height());
1957 pb->show();
1958 pb->update();
1959 }
1960
1961 void
1918 View::progressCheckStalledTimerElapsed() 1962 View::progressCheckStalledTimerElapsed()
1919 { 1963 {
1920 QObject *s = sender(); 1964 QObject *s = sender();
1921 QTimer *t = qobject_cast<QTimer *>(s); 1965 QTimer *t = qobject_cast<QTimer *>(s);
1922 if (!t) return; 1966 if (!t) return;
1923 1967
1924 for (ProgressMap::iterator i = m_progressBars.begin(); 1968 for (ProgressMap::iterator i = m_progressBars.begin();
1925 i != m_progressBars.end(); ++i) { 1969 i != m_progressBars.end(); ++i) {
1926 1970
1927 if (i->second.checkTimer == t) { 1971 if (i->second.stallCheckTimer == t) {
1928 1972
1929 int value = i->second.bar->value(); 1973 int value = i->second.bar->value();
1930 1974
1931 #ifdef DEBUG_PROGRESS_STUFF 1975 #ifdef DEBUG_PROGRESS_STUFF
1932 SVCERR << "View[" << getId() << "]::progressCheckStalledTimerElapsed for layer " << i->first << ": value is " << value << endl; 1976 SVCERR << "View[" << getId() << "]::progressCheckStalledTimerElapsed for layer " << i->first << ": value is " << value << endl;
1933 #endif 1977 #endif
1934 1978
1935 if (value > 0 && value == i->second.lastCheck) { 1979 if (value > 0 && value == i->second.lastStallCheckValue) {
1936 i->second.bar->setMaximum(0); // indeterminate 1980 i->second.bar->setMaximum(0); // indeterminate
1937 } 1981 }
1938 i->second.lastCheck = value; 1982 i->second.lastStallCheckValue = value;
1939 return; 1983 return;
1940 } 1984 }
1941 } 1985 }
1942 } 1986 }
1943 1987
1944 int 1988 int
1945 View::getProgressBarWidth() const 1989 View::getProgressBarWidth() const
1946 { 1990 {
1991 if (m_alignmentProgressBar.bar) {
1992 return m_alignmentProgressBar.bar->width();
1993 }
1994
1947 for (ProgressMap::const_iterator i = m_progressBars.begin(); 1995 for (ProgressMap::const_iterator i = m_progressBars.begin();
1948 i != m_progressBars.end(); ++i) { 1996 i != m_progressBars.end(); ++i) {
1949 if (i->second.bar && i->second.bar->isVisible()) { 1997 if (i->second.bar && i->second.bar->isVisible()) {
1950 return i->second.bar->width(); 1998 return i->second.bar->width();
1951 } 1999 }