Mercurial > hg > svcore
comparison data/model/SparseModel.h @ 1239:5261a7791f1c 3.0-integration
Merge from branch piper
author | Chris Cannam |
---|---|
date | Fri, 28 Oct 2016 15:20:58 +0100 |
parents | 771a17925576 |
children | cbdd534f517a |
comparison
equal
deleted
inserted
replaced
1221:a1b97df9962e | 1239:5261a7791f1c |
---|---|
728 SparseModel<PointType>::setResolution(int resolution) | 728 SparseModel<PointType>::setResolution(int resolution) |
729 { | 729 { |
730 { | 730 { |
731 QMutexLocker locker(&m_mutex); | 731 QMutexLocker locker(&m_mutex); |
732 m_resolution = resolution; | 732 m_resolution = resolution; |
733 } | 733 m_rows.clear(); |
734 m_rows.clear(); | 734 } |
735 emit modelChanged(); | 735 emit modelChanged(); |
736 } | 736 } |
737 | 737 |
738 template <typename PointType> | 738 template <typename PointType> |
739 void | 739 void |
741 { | 741 { |
742 { | 742 { |
743 QMutexLocker locker(&m_mutex); | 743 QMutexLocker locker(&m_mutex); |
744 m_points.clear(); | 744 m_points.clear(); |
745 m_pointCount = 0; | 745 m_pointCount = 0; |
746 } | 746 m_rows.clear(); |
747 m_rows.clear(); | 747 } |
748 emit modelChanged(); | 748 emit modelChanged(); |
749 } | 749 } |
750 | 750 |
751 template <typename PointType> | 751 template <typename PointType> |
752 void | 752 void |
753 SparseModel<PointType>::addPoint(const PointType &point) | 753 SparseModel<PointType>::addPoint(const PointType &point) |
754 { | 754 { |
755 { | 755 QMutexLocker locker(&m_mutex); |
756 QMutexLocker locker(&m_mutex); | 756 |
757 m_points.insert(point); | 757 m_points.insert(point); |
758 m_pointCount++; | 758 m_pointCount++; |
759 if (point.getLabel() != "") m_hasTextLabels = true; | 759 if (point.getLabel() != "") m_hasTextLabels = true; |
760 } | |
761 | 760 |
762 // Even though this model is nominally sparse, there may still be | 761 // Even though this model is nominally sparse, there may still be |
763 // too many signals going on here (especially as they'll probably | 762 // too many signals going on here (especially as they'll probably |
764 // be queued from one thread to another), which is why we need the | 763 // be queued from one thread to another), which is why we need the |
765 // notifyOnAdd as an option rather than a necessity (the | 764 // notifyOnAdd as an option rather than a necessity (the |
782 | 781 |
783 template <typename PointType> | 782 template <typename PointType> |
784 bool | 783 bool |
785 SparseModel<PointType>::containsPoint(const PointType &point) | 784 SparseModel<PointType>::containsPoint(const PointType &point) |
786 { | 785 { |
787 { | 786 QMutexLocker locker(&m_mutex); |
788 QMutexLocker locker(&m_mutex); | 787 |
789 | 788 PointListIterator i = m_points.lower_bound(point); |
790 PointListIterator i = m_points.lower_bound(point); | 789 typename PointType::Comparator comparator; |
791 typename PointType::Comparator comparator; | 790 while (i != m_points.end()) { |
792 while (i != m_points.end()) { | 791 if (i->frame > point.frame) break; |
793 if (i->frame > point.frame) break; | 792 if (!comparator(*i, point) && !comparator(point, *i)) { |
794 if (!comparator(*i, point) && !comparator(point, *i)) { | 793 return true; |
795 return true; | 794 } |
795 ++i; | |
796 } | |
797 | |
798 return false; | |
799 } | |
800 | |
801 template <typename PointType> | |
802 void | |
803 SparseModel<PointType>::deletePoint(const PointType &point) | |
804 { | |
805 QMutexLocker locker(&m_mutex); | |
806 | |
807 PointListIterator i = m_points.lower_bound(point); | |
808 typename PointType::Comparator comparator; | |
809 while (i != m_points.end()) { | |
810 if (i->frame > point.frame) break; | |
811 if (!comparator(*i, point) && !comparator(point, *i)) { | |
812 m_points.erase(i); | |
813 m_pointCount--; | |
814 break; | |
796 } | 815 } |
797 ++i; | 816 ++i; |
798 } | 817 } |
799 } | 818 |
800 | |
801 return false; | |
802 } | |
803 | |
804 template <typename PointType> | |
805 void | |
806 SparseModel<PointType>::deletePoint(const PointType &point) | |
807 { | |
808 { | |
809 QMutexLocker locker(&m_mutex); | |
810 | |
811 PointListIterator i = m_points.lower_bound(point); | |
812 typename PointType::Comparator comparator; | |
813 while (i != m_points.end()) { | |
814 if (i->frame > point.frame) break; | |
815 if (!comparator(*i, point) && !comparator(point, *i)) { | |
816 m_points.erase(i); | |
817 m_pointCount--; | |
818 break; | |
819 } | |
820 ++i; | |
821 } | |
822 } | |
823 // std::cout << "SparseOneDimensionalModel: emit modelChanged(" | 819 // std::cout << "SparseOneDimensionalModel: emit modelChanged(" |
824 // << point.frame << ")" << std::endl; | 820 // << point.frame << ")" << std::endl; |
825 m_rows.clear(); //!!! inefficient | 821 m_rows.clear(); //!!! inefficient |
826 emit modelChangedWithin(point.frame, point.frame + m_resolution); | 822 emit modelChangedWithin(point.frame, point.frame + m_resolution); |
827 } | 823 } |
829 template <typename PointType> | 825 template <typename PointType> |
830 void | 826 void |
831 SparseModel<PointType>::setCompletion(int completion, bool update) | 827 SparseModel<PointType>::setCompletion(int completion, bool update) |
832 { | 828 { |
833 // std::cerr << "SparseModel::setCompletion(" << completion << ")" << std::endl; | 829 // std::cerr << "SparseModel::setCompletion(" << completion << ")" << std::endl; |
830 | |
831 QMutexLocker locker(&m_mutex); | |
834 | 832 |
835 if (m_completion != completion) { | 833 if (m_completion != completion) { |
836 m_completion = completion; | 834 m_completion = completion; |
837 | 835 |
838 if (completion == 100) { | 836 if (completion == 100) { |