provide a user interface to edit motifs
[mussa.git] / qui / motif_editor / MotifEditor.cpp
1 #include "qui/motif_editor/MotifEditor.hpp"
2 #include "alg/sequence.hpp"
3
4 #include <set>
5 #include <string>
6
7 using namespace std;
8
9 MotifEditor::MotifEditor(Mussa *m, QWidget *parent)
10   : QWidget(parent),
11     analysis(m),
12     applyButton("set motifs")
13 {
14   assert (m != 0);
15   const set<string> &motif = analysis->motifs();
16   vector<string> motif_seq(motif.begin(), motif.end());
17
18   connect(&applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs()));
19   layout.addWidget(&applyButton);
20
21   for(size_t i=0; i != 10; ++i)
22   {
23     MotifDetail *detail = new MotifDetail;
24     if (i < motif_seq.size()) {
25       detail->setMotif(motif_seq[i]);
26       detail->setColor(analysis->colorMapper().lookup("motif", motif_seq[i]));
27     }
28     motif_details.push_back(detail);
29     layout.addWidget(detail);
30   }
31   setLayout(&layout);
32 }
33
34 MotifEditor::MotifEditor(const MotifEditor& me)
35   : QWidget((QWidget*)me.parent()),
36     analysis(me.analysis),
37     applyButton(me.applyButton.text())
38 {
39 }
40
41 void MotifEditor::updateMotifs()
42 {
43   // This function is _sooo_ not thread safe
44   // erase motifs
45   Color motif_default = analysis->colorMapper().typeColor("motif");
46   analysis->colorMapper().erase("motif");
47   analysis->colorMapper().appendTypeColor("motif", motif_default);
48
49   // add our motifs back
50   vector<string> motifs;
51   vector<Color> colors;
52
53   for(std::vector<MotifDetail *>::iterator md_i =  motif_details.begin();
54       md_i != motif_details.end();
55       ++md_i)
56   {
57     if ((*md_i)->motif().size() > 0) {
58       motifs.push_back((*md_i)->motif());
59       colors.push_back((*md_i)->color());
60     }
61   }
62   analysis->add_motifs(motifs, colors);
63
64   emit changedMotifs();
65 }
66
67 //MotifEditor::
68