implement set window state
authorDiane Trout <diane@caltech.edu>
Fri, 27 Oct 2006 17:57:05 +0000 (17:57 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 27 Oct 2006 17:57:05 +0000 (17:57 +0000)
ticket:194
basically works, though I need to get mussa to notice when sequence
information has been changed.

alg/mussa.cpp
alg/mussa.hpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp

index 6978ef24356f0775ead016f6deabb8aabe9bbca1..58558ff6e14b498c3679c7bcc4dfea41fc5223dc 100644 (file)
@@ -79,7 +79,15 @@ Mussa::clear()
   the_seqs.clear();
   the_paths.clear();
   analysis_path = fs::path();
-  dirty = false;
+  set_dirty(false);
+}
+
+void Mussa::set_dirty(bool new_state)
+{
+  if (dirty != new_state) {
+    dirty = new_state;
+    emit isModified(dirty);
+  }
 }
 
 bool Mussa::is_dirty() const
@@ -100,7 +108,7 @@ void
 Mussa::set_name(string a_name)
 {
   analysis_name = a_name;
-  dirty = true;
+  set_dirty(true);
 }
 
 string Mussa::get_name() const
@@ -133,7 +141,7 @@ void
 Mussa::set_window(int a_window)
 {
   window = a_window;
-  dirty = true;
+  set_dirty(true);
 }
 
 int Mussa::get_window() const
@@ -145,7 +153,7 @@ void
 Mussa::set_threshold(int a_threshold)
 {
   threshold = a_threshold;
-  dirty = true;
+  set_dirty(true);
   if (a_threshold > soft_thres) {
     soft_thres = a_threshold;
   }
@@ -177,7 +185,7 @@ void
 Mussa::set_analysis_mode(enum analysis_modes new_ana_mode)
 {
   ana_mode = new_ana_mode;
-  dirty = true;
+  set_dirty(true);
 }
 
 enum Mussa::analysis_modes Mussa::get_analysis_mode() const
@@ -304,13 +312,13 @@ void Mussa::append_sequence(const Sequence& a_seq)
 {
   boost::shared_ptr<Sequence> seq_copy(new Sequence(a_seq));
   the_seqs.push_back(seq_copy);
-  dirty = true;
+  set_dirty(true);
 }
 
 void Mussa::append_sequence(boost::shared_ptr<Sequence> a_seq)
 {
   the_seqs.push_back(a_seq);
-  dirty = true;
+  set_dirty(true);
 }
 
 
@@ -333,7 +341,7 @@ void Mussa::load_sequence(fs::path seq_file, fs::path annot_file,
     aseq->set_species(*name);
   }
   the_seqs.push_back(aseq);
-  dirty = true;
+  set_dirty(true);
 }
 
 void
@@ -449,7 +457,7 @@ Mussa::load_mupa_file(fs::path para_file_path)
     //     << " threshold = " << threshold << endl;
   }
   // no file was loaded, signal error
-  dirty = true;
+  set_dirty(true);
 }
 
 
@@ -602,7 +610,7 @@ Mussa::save(fs::path save_path)
     }
   }
 
-  dirty = false;
+  set_dirty(false);
   analysis_path = save_path;
 }
 
@@ -752,7 +760,7 @@ void Mussa::add_motif(const Sequence& motif, const Color& color)
 {
   motif_sequences.insert(motif);
   color_mapper->appendInstanceColor("motif", motif.get_sequence(), color);
-  dirty = true;
+  set_dirty(true);
 }
 
 void Mussa::set_motifs(const vector<Sequence>& motifs, 
index 27cd239f41c78091abda71fb58f1b95190307da7..e85055d3bf6acb32338341909d422ec3e912e7a3 100644 (file)
@@ -38,6 +38,8 @@ class Mussa : public QObject
 signals:
     //! call whatever signaling system we want
     void progress(const std::string& description, int cur, int max);
+    //! triggered when our state changes between unsaved(true) and saved(false)
+    void isModified(bool);
 
 public:
     typedef std::set<Sequence> motif_set;
@@ -100,6 +102,8 @@ public:
     enum analysis_modes get_analysis_mode() const;
     //! return a string name for an analysis mode
     std::string get_analysis_mode_name() const;
+    //! set our current dirty state
+    void set_dirty(bool);
     //! return if we have unsaved changes
     bool is_dirty() const;
     //! is there anything loaded into this analysis?
index df892af4d4461fc568607af45b91ef262a77d151..162598487cd68778d9a57a0fa5d9e8efb26f26a8 100644 (file)
@@ -100,6 +100,8 @@ MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) :
   if (analysis) {
     connect(analysis.get(), SIGNAL(progress(const std::string&, int, int)),
             this, SLOT(updateProgress(const std::string&, int, int)));
+    connect(analysis.get(), SIGNAL(isModified(bool)),
+            this, SLOT(updateAnalysisModified(bool)));        
   }
   updateTitle();
   updateAnalysis();
@@ -793,9 +795,16 @@ MussaWindow::updateProgress(const string& description, int current, int max)
   qApp->processEvents();
 }
 
+void MussaWindow::updateAnalysisModified(bool is_modified)
+{
+  setWindowModified(is_modified);
+}
+
 void MussaWindow::updateTitle()
 {
   if (analysis) {
-    setWindowTitle(analysis->get_title().c_str());
+    QString title(analysis->get_title().c_str());
+    title += "[*]";
+    setWindowTitle(title);
   }
 }
index efa370697ee82422b10e8a56630d219f72f2de75..acec825b11fa3161a5b1cbc3750424f74e935ce7 100644 (file)
@@ -57,6 +57,8 @@ public slots:
   void saveAnalysis();
   //! save an analysis after prompting for new name
   void saveAnalysisAs();
+  //! set the window modified flag
+  void updateAnalysisModified(bool);
   //! try to conver the mussa analysis_path to a title
   void updateTitle();
   //\@}