comparison view/View.cpp @ 1459:42c87368287c

Merge from branch single-point
author Chris Cannam
date Fri, 17 May 2019 10:02:52 +0100
parents 009f22e03bf6
children 84c4ddb38415
comparison
equal deleted inserted replaced
1441:8d5bf4ab98ef 1459:42c87368287c
48 #include <cassert> 48 #include <cassert>
49 #include <cmath> 49 #include <cmath>
50 50
51 //#define DEBUG_VIEW 1 51 //#define DEBUG_VIEW 1
52 //#define DEBUG_VIEW_WIDGET_PAINT 1 52 //#define DEBUG_VIEW_WIDGET_PAINT 1
53 //#define DEBUG_PROGRESS_STUFF 1
53 54
54 View::View(QWidget *w, bool showProgress) : 55 View::View(QWidget *w, bool showProgress) :
55 QFrame(w), 56 QFrame(w),
56 m_id(getNextId()), 57 m_id(getNextId()),
57 m_centreFrame(0), 58 m_centreFrame(0),
232 std::map<int, Layer *> sortedLayers; 233 std::map<int, Layer *> sortedLayers;
233 234
234 for (LayerList::const_iterator i = m_layerStack.begin(); 235 for (LayerList::const_iterator i = m_layerStack.begin();
235 i != m_layerStack.end(); ++i) { 236 i != m_layerStack.end(); ++i) {
236 if ((*i)->needsTextLabelHeight()) { 237 if ((*i)->needsTextLabelHeight()) {
237 sortedLayers[getObjectExportId(*i)] = *i; 238 sortedLayers[(*i)->getExportId()] = *i;
238 } 239 }
239 } 240 }
240 241
241 int y = scalePixelSize(15) + paint.fontMetrics().ascent(); 242 int y = scalePixelSize(15) + paint.fontMetrics().ascent();
242 243
1734 } 1735 }
1735 1736
1736 void 1737 void
1737 View::checkProgress(void *object) 1738 View::checkProgress(void *object)
1738 { 1739 {
1739 if (!m_showProgress) return; 1740 if (!m_showProgress) {
1740 1741 #ifdef DEBUG_PROGRESS_STUFF
1742 SVCERR << "View[" << this << "]::checkProgress(" << object << "): "
1743 << "m_showProgress is off" << endl;
1744 #endif
1745 return;
1746 }
1747
1748 QSettings settings;
1749 settings.beginGroup("View");
1750 bool showCancelButton = settings.value("showcancelbuttons", true).toBool();
1751 settings.endGroup();
1752
1741 int ph = height(); 1753 int ph = height();
1754 bool found = false;
1742 1755
1743 for (ProgressMap::iterator i = m_progressBars.begin(); 1756 for (ProgressMap::iterator i = m_progressBars.begin();
1744 i != m_progressBars.end(); ++i) { 1757 i != m_progressBars.end(); ++i) {
1745 1758
1746 QProgressBar *pb = i->second.bar; 1759 QProgressBar *pb = i->second.bar;
1747 QPushButton *cancel = i->second.cancel; 1760 QPushButton *cancel = i->second.cancel;
1748 1761
1749 if (i->first == object) { 1762 if (i->first == object) {
1750 1763
1764 found = true;
1765
1766 if (i->first->isLayerDormant(this)) {
1767 // A dormant (invisible) layer can still be busy
1768 // generating, but we don't usually want to indicate
1769 // it because it probably means it's a duplicate of a
1770 // visible layer
1771 cancel->hide();
1772 pb->hide();
1773 continue;
1774 }
1775
1751 // The timer is used to test for stalls. If the progress 1776 // The timer is used to test for stalls. If the progress
1752 // bar does not get updated for some length of time, the 1777 // bar does not get updated for some length of time, the
1753 // timer prompts it to go back into "indeterminate" mode 1778 // timer prompts it to go back into "indeterminate" mode
1754 QTimer *timer = i->second.checkTimer; 1779 QTimer *timer = i->second.checkTimer;
1755 1780
1756 int completion = i->first->getCompletion(this); 1781 int completion = i->first->getCompletion(this);
1757 QString text = i->first->getPropertyContainerName(); 1782 QString text = i->first->getPropertyContainerName();
1758 QString error = i->first->getError(this); 1783 QString error = i->first->getError(this);
1784
1785 #ifdef DEBUG_PROGRESS_STUFF
1786 SVCERR << "View[" << this << "]::checkProgress(" << object << "): "
1787 << "found progress bar " << pb << " for layer at height " << ph
1788 << ": completion = " << completion << endl;
1789 #endif
1759 1790
1760 if (error != "" && error != m_lastError) { 1791 if (error != "" && error != m_lastError) {
1761 QMessageBox::critical(this, tr("Layer rendering error"), error); 1792 QMessageBox::critical(this, tr("Layer rendering error"), error);
1762 m_lastError = error; 1793 m_lastError = error;
1763 } 1794 }
1776 if (wfm || 1807 if (wfm ||
1777 (model && 1808 (model &&
1778 (wfm = dynamic_cast<RangeSummarisableTimeValueModel *> 1809 (wfm = dynamic_cast<RangeSummarisableTimeValueModel *>
1779 (model->getSourceModel())))) { 1810 (model->getSourceModel())))) {
1780 completion = wfm->getAlignmentCompletion(); 1811 completion = wfm->getAlignmentCompletion();
1781 // SVDEBUG << "View::checkProgress: Alignment completion = " << completion << endl; 1812
1813 #ifdef DEBUG_PROGRESS_STUFF
1814 SVCERR << "View[" << this << "]::checkProgress(" << object << "): "
1815 << "alignment completion = " << completion << endl;
1816 #endif
1817
1782 if (completion < 100) { 1818 if (completion < 100) {
1783 text = tr("Alignment"); 1819 text = tr("Alignment");
1784 } 1820 }
1785 } 1821 }
1786 1822
1793 pb->hide(); 1829 pb->hide();
1794 cancel->hide(); 1830 cancel->hide();
1795 timer->stop(); 1831 timer->stop();
1796 1832
1797 } else { 1833 } else {
1798
1799 // cerr << "progress = " << completion << endl;
1800 1834
1801 if (!pb->isVisible()) { 1835 if (!pb->isVisible()) {
1802 i->second.lastCheck = 0; 1836 i->second.lastCheck = 0;
1803 timer->setInterval(2000); 1837 timer->setInterval(2000);
1804 timer->start(); 1838 timer->start();
1805 } 1839 }
1806 1840
1807 int scaled20 = scalePixelSize(20); 1841 if (showCancelButton) {
1808 1842
1809 cancel->move(0, ph - pb->height()/2 - scaled20/2); 1843 int scaled20 = scalePixelSize(20);
1810 cancel->show(); 1844
1811 1845 cancel->move(0, ph - pb->height()/2 - scaled20/2);
1812 pb->setValue(completion); 1846 cancel->show();
1813 pb->move(scaled20, ph - pb->height()); 1847
1848 pb->setValue(completion);
1849 pb->move(scaled20, ph - pb->height());
1850
1851 } else {
1852
1853 cancel->hide();
1854
1855 pb->setValue(completion);
1856 pb->move(0, ph - pb->height());
1857 }
1814 1858
1815 pb->show(); 1859 pb->show();
1816 pb->update(); 1860 pb->update();
1817 1861
1818 ph -= pb->height(); 1862 ph -= pb->height();
1821 if (pb->isVisible()) { 1865 if (pb->isVisible()) {
1822 ph -= pb->height(); 1866 ph -= pb->height();
1823 } 1867 }
1824 } 1868 }
1825 } 1869 }
1870
1871 if (!found) {
1872 #ifdef DEBUG_PROGRESS_STUFF
1873 SVCERR << "View[" << this << "]::checkProgress(" << object << "): "
1874 << "failed to find layer " << object << " in progress map"
1875 << endl;
1876 #endif
1877 }
1826 } 1878 }
1827 1879
1828 void 1880 void
1829 View::progressCheckStalledTimerElapsed() 1881 View::progressCheckStalledTimerElapsed()
1830 { 1882 {
1831 QObject *s = sender(); 1883 QObject *s = sender();
1832 QTimer *t = qobject_cast<QTimer *>(s); 1884 QTimer *t = qobject_cast<QTimer *>(s);
1833 if (!t) return; 1885 if (!t) return;
1886
1834 for (ProgressMap::iterator i = m_progressBars.begin(); 1887 for (ProgressMap::iterator i = m_progressBars.begin();
1835 i != m_progressBars.end(); ++i) { 1888 i != m_progressBars.end(); ++i) {
1889
1836 if (i->second.checkTimer == t) { 1890 if (i->second.checkTimer == t) {
1891
1892 #ifdef DEBUG_PROGRESS_STUFF
1893 SVCERR << "View[" << this << "]::progressCheckStalledTimerElapsed for layer " << i->first << endl;
1894 #endif
1895
1837 int value = i->second.bar->value(); 1896 int value = i->second.bar->value();
1838 if (value > 0 && value == i->second.lastCheck) { 1897 if (value > 0 && value == i->second.lastCheck) {
1839 i->second.bar->setMaximum(0); // indeterminate 1898 i->second.bar->setMaximum(0); // indeterminate
1840 } 1899 }
1841 i->second.lastCheck = value; 1900 i->second.lastCheck = value;