comparison layer/RegionLayer.cpp @ 552:2e8194a30f40 sv-v1.7.1

* Layer data editor window: fix sorting for columns in region model, add Find feature * RDF import: assign names to layers based on event types, if no suitable labels are found in the RDF * Add label to status bar showing the last text that was passed in current layer (so e.g. counting 1, 2, 3, 4 if that's what beats are labelled) * Better layout of text labels for region layers in segmentation mode when they are close together * Give text layer the same method for finding "nearest point" as region and note layers, should improve its editability
author Chris Cannam
date Thu, 22 Oct 2009 15:54:21 +0000
parents c2ba2796cbee
children 5bcfc5606528
comparison
equal deleted inserted replaced
551:c2ba2796cbee 552:2e8194a30f40
348 p = *i; 348 p = *i;
349 } 349 }
350 } 350 }
351 351
352 return true; 352 return true;
353 }
354
355 QString
356 RegionLayer::getLabelPreceding(size_t frame) const
357 {
358 if (!m_model) return "";
359 RegionModel::PointList points = m_model->getPreviousPoints(frame);
360 for (RegionModel::PointList::const_iterator i = points.begin();
361 i != points.end(); ++i) {
362 if (i->label != "") return i->label;
363 }
364 return "";
353 } 365 }
354 366
355 QString 367 QString
356 RegionLayer::getFeatureDescription(View *v, QPoint &pos) const 368 RegionLayer::getFeatureDescription(View *v, QPoint &pos) const
357 { 369 {
749 int sampleRate = m_model->getSampleRate(); 761 int sampleRate = m_model->getSampleRate();
750 if (!sampleRate) return; 762 if (!sampleRate) return;
751 763
752 // Profiler profiler("RegionLayer::paint", true); 764 // Profiler profiler("RegionLayer::paint", true);
753 765
754 int x0 = rect.left(), x1 = rect.right(); 766 int x0 = rect.left() - 40, x1 = rect.right();
755 long frame0 = v->getFrameForX(x0); 767 long frame0 = v->getFrameForX(x0);
756 long frame1 = v->getFrameForX(x1); 768 long frame1 = v->getFrameForX(x1);
757 769
758 RegionModel::PointList points(m_model->getPoints(frame0, frame1)); 770 RegionModel::PointList points(m_model->getPoints(frame0, frame1));
759 if (points.empty()) return; 771 if (points.empty()) return;
824 } else { 836 } else {
825 paint.setPen(getBaseQColor()); 837 paint.setPen(getBaseQColor());
826 paint.setBrush(brushColour); 838 paint.setBrush(brushColour);
827 } 839 }
828 840
829 bool illuminated = false;
830
831 if (m_plotStyle == PlotSegmentation) { 841 if (m_plotStyle == PlotSegmentation) {
832 842
833 if (ex <= x) continue; 843 if (ex <= x) continue;
834 844
835 if (!shouldIlluminate || 845 if (!shouldIlluminate ||
836 // "illuminatePoint != p" 846 // "illuminatePoint != p"
837 RegionModel::Point::Comparator()(illuminatePoint, p) || 847 RegionModel::Point::Comparator()(illuminatePoint, p) ||
838 RegionModel::Point::Comparator()(p, illuminatePoint)) { 848 RegionModel::Point::Comparator()(p, illuminatePoint)) {
839 849
840 // if (illuminateFrame != p.frame && 850 paint.drawLine(x, 0, x, v->height());
841 // (ex < x + 5 || x >= v->width() - 1)) {
842 paint.setPen(Qt::NoPen); 851 paint.setPen(Qt::NoPen);
852
853 } else {
854 paint.setPen(QPen(getForegroundQColor(v), 2));
843 } 855 }
844 856
845 paint.drawRect(x, -1, ex - x, v->height() + 1); 857 paint.drawRect(x, 0, ex - x, v->height() + 1);
846 858
847 } else { 859 } else {
848 860
849 if (shouldIlluminate && 861 if (shouldIlluminate &&
850 // "illuminatePoint == p" 862 // "illuminatePoint == p"
865 (p.frame, m_model->getSampleRate()).toText(true).c_str(); 877 (p.frame, m_model->getSampleRate()).toText(true).c_str();
866 v->drawVisibleText(paint, 878 v->drawVisibleText(paint,
867 x, 879 x,
868 y - h/2 - paint.fontMetrics().descent() - 2, 880 y - h/2 - paint.fontMetrics().descent() - 2,
869 hlabel, View::OutlinedText); 881 hlabel, View::OutlinedText);
870
871 illuminated = true;
872 } 882 }
873 883
874 paint.drawLine(x, y-1, x + w, y-1); 884 paint.drawLine(x, y-1, x + w, y-1);
875 paint.drawLine(x, y+1, x + w, y+1); 885 paint.drawLine(x, y+1, x + w, y+1);
876 paint.drawLine(x, y - h/2, x, y + h/2); 886 paint.drawLine(x, y - h/2, x, y + h/2);
877 paint.drawLine(x+w, y - h/2, x + w, y + h/2); 887 paint.drawLine(x+w, y - h/2, x + w, y + h/2);
878 } 888 }
889 }
890
891 int nextLabelMinX = -100;
892 int lastLabelY = 0;
893
894 for (RegionModel::PointList::const_iterator i = points.begin();
895 i != points.end(); ++i) {
896
897 const RegionModel::Point &p(*i);
898
899 int x = v->getXForFrame(p.frame);
900 int y = getYForValue(v, p.value);
901
902 bool illuminated = false;
903
904 if (m_plotStyle != PlotSegmentation) {
905
906 if (shouldIlluminate &&
907 // "illuminatePoint == p"
908 !RegionModel::Point::Comparator()(illuminatePoint, p) &&
909 !RegionModel::Point::Comparator()(p, illuminatePoint)) {
910
911 illuminated = true;
912 }
913 }
879 914
880 if (!illuminated) { 915 if (!illuminated) {
881 QString label = p.label; 916 QString label = p.label;
882 if (label == "") { 917 if (label == "") {
883 label = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); 918 label = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits());
884 } 919 }
885 920
921 int labelX, labelY;
922
886 if (m_plotStyle != PlotSegmentation) { 923 if (m_plotStyle != PlotSegmentation) {
887 v->drawVisibleText(paint, 924 labelX = x - paint.fontMetrics().width(label) - 2;
888 x - paint.fontMetrics().width(label) - 2, 925 labelY = y + paint.fontMetrics().height()/2
889 y + paint.fontMetrics().height()/2 926 - paint.fontMetrics().descent();
890 - paint.fontMetrics().descent(),
891 label, View::OutlinedText);
892 } else { 927 } else {
893 v->drawVisibleText(paint, 928 labelX = x + 5;
894 x + 5, 929 labelY = v->getTextLabelHeight(this, paint);
895 v->getTextLabelHeight(this, paint), 930 if (labelX < nextLabelMinX) {
896 label, View::OutlinedText); 931 if (lastLabelY < v->height()/2) {
932 labelY = lastLabelY + fontHeight;
933 }
934 }
935 lastLabelY = labelY;
936 nextLabelMinX = labelX + paint.fontMetrics().width(label);
897 } 937 }
938
939 v->drawVisibleText(paint, labelX, labelY, label, View::OutlinedText);
898 } 940 }
899 } 941 }
900 942
901 paint.restore(); 943 paint.restore();
902 } 944 }
1099 1141
1100 bool 1142 bool
1101 RegionLayer::editOpen(View *v, QMouseEvent *e) 1143 RegionLayer::editOpen(View *v, QMouseEvent *e)
1102 { 1144 {
1103 if (!m_model) return false; 1145 if (!m_model) return false;
1104 /*
1105 RegionModel::PointList points = getLocalPoints(v, e->x());
1106 if (points.empty()) return false;
1107 */
1108 1146
1109 RegionModel::Point region(0); 1147 RegionModel::Point region(0);
1110 if (!getPointToDrag(v, e->x(), e->y(), region)) return false; 1148 if (!getPointToDrag(v, e->x(), e->y(), region)) return false;
1111
1112 // RegionModel::Point region = *points.begin();
1113 1149
1114 ItemEditDialog *dialog = new ItemEditDialog 1150 ItemEditDialog *dialog = new ItemEditDialog
1115 (m_model->getSampleRate(), 1151 (m_model->getSampleRate(),
1116 ItemEditDialog::ShowTime | 1152 ItemEditDialog::ShowTime |
1117 ItemEditDialog::ShowDuration | 1153 ItemEditDialog::ShowDuration |