Implemented the 'edit entry' action.

Sun, 21 Oct 2012 17:03:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 21 Oct 2012 17:03:22 +0200
changeset 12
6c91abc72022
parent 11
1eabdd26c44e
child 13
402a0962c225

Implemented the 'edit entry' action.

PluginTimeTracker.e4p file | annotate | diff | comparison | revisions
TimeTracker/TimeTrackEntry.py file | annotate | diff | comparison | revisions
TimeTracker/TimeTracker.py file | annotate | diff | comparison | revisions
TimeTracker/TimeTrackerWidget.py file | annotate | diff | comparison | revisions
--- a/PluginTimeTracker.e4p	Sun Oct 21 15:33:36 2012 +0200
+++ b/PluginTimeTracker.e4p	Sun Oct 21 17:03:22 2012 +0200
@@ -21,6 +21,7 @@
     <Source>TimeTracker/TimeTrackerWidget.py</Source>
     <Source>TimeTracker/ConfigurationPage/__init__.py</Source>
     <Source>TimeTracker/ConfigurationPage/TimeTrackerPage.py</Source>
+    <Source>TimeTracker/TimeTrackerEntryDialog.py</Source>
   </Sources>
   <Forms>
     <Form>TimeTracker/TimeTrackerEntryDialog.ui</Form>
--- a/TimeTracker/TimeTrackEntry.py	Sun Oct 21 15:33:36 2012 +0200
+++ b/TimeTracker/TimeTrackEntry.py	Sun Oct 21 17:03:22 2012 +0200
@@ -183,6 +183,14 @@
         
         return minutes
     
+    def getID(self):
+        """
+        Public method to get the ID of the entry.
+        
+        @return ID of the entry (integer)
+        """
+        return self.__id
+    
     def setID(self, eid):
         """
         Public method to assign an ID to the entry.
@@ -191,6 +199,58 @@
         """
         self.__id = eid
     
+    def getStartDateTime(self):
+        """
+        Public method to get the start date and time.
+        
+        @return start date and time (QDateTime)
+        """
+        return self.__startDateTime
+    
+    def setStartDateTime(self, startDateTime):
+        """
+        Public method to set the start date and time.
+        
+        @param startDateTime start date and time (QDateTime)
+        """
+        if startDateTime.isValid():
+            self.__startDateTime = startDateTime
+    
+    def getDuration(self):
+        """
+        Public slot to get the duration.
+        
+        @return duration (integer)
+        """
+        return self.__duration
+    
+    def setDuration(self, duration):
+        """
+        Public method to set the duration.
+        
+        @param duration duration in minutes (integer)
+        """
+        if duration >= 0:
+            self.__duration = duration
+    
+    def addDuration(self, duration):
+        """
+        Public method to add a duration.
+        
+        @param duration duration to be added in minutes (integer). Negative values
+            are ignored.
+        """
+        if duration > 0:
+            self.__duration += duration
+    
+    def getTask(self):
+        """
+        Public method to get the task description.
+        
+        @return task description (string)
+        """
+        return self.__task
+    
     def setTask(self, description):
         """
         Public method to set the task description.
@@ -201,6 +261,14 @@
                                  .replace("\n", " ")\
                                  .replace("\r", " ")
     
+    def getComment(self):
+        """
+        Public method to get the comment.
+        
+        @return comment (string)
+        """
+        return self.__comment
+    
     def setComment(self, comment):
         """
         Public method to set a comment.
@@ -211,16 +279,6 @@
                                 .replace("\n", " ")\
                                 .replace("\r", " ")
     
-    def addDuration(self, duration):
-        """
-        Public method to add a duration.
-        
-        @param duration duration to be added in minutes (integer). Negative values
-            are ignored.
-        """
-        if duration > 0:
-            self.__duration += duration
-    
     def getEntryData(self):
         """
         Public method to get the entry data.
@@ -238,27 +296,3 @@
             self.__comment,
             self.__paused,
         )
-    
-    def getStartDateTime(self):
-        """
-        Public method to get the start date and time.
-        
-        @return start date and time (QDateTime)
-        """
-        return self.__startDateTime
-    
-    def getDuration(self):
-        """
-        Public slot to get the duration.
-        
-        @return duration (integer)
-        """
-        return self.__duration
-    
-    def getID(self):
-        """
-        Public method to get the ID of the entry.
-        
-        @return ID of the entry (integer)
-        """
-        return self.__id
--- a/TimeTracker/TimeTracker.py	Sun Oct 21 15:33:36 2012 +0200
+++ b/TimeTracker/TimeTracker.py	Sun Oct 21 17:03:22 2012 +0200
@@ -59,6 +59,7 @@
         self.__currentEntry = None
         
         self.__widget.clear()
+        self.__widget.setEnabled(False)
     
     def projectOpened(self):
         """
@@ -75,6 +76,7 @@
         
         self.__readTrackerEntries()
         self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True))
+        self.__widget.setEnabled(True)
         
         self.startTrackerEntry()
     
@@ -269,6 +271,18 @@
         """
         return self.__currentEntry
     
+    def getEntry(self, eid):
+        """
+        Public method to get a tracker entry given its ID.
+        
+        @param eid ID of the tracker entry (integer)
+        @return entry for the given ID (TimeTrackEntry) or None
+        """
+        if eid in self.__entries:
+            return self.__entries[eid]
+        else:
+            return None
+    
     def deleteTrackerEntry(self, eid):
         """
         Public method to delete a tracker entry given its ID.
@@ -336,3 +350,10 @@
         self.__widget.clear()
         self.__widget.showTrackerEntries(sorted(self.__entries.values(), reverse=True))
         self.__widget.setCurrentEntry(self.__currentEntry)
+    
+    def entryChanged(self):
+        """
+        Public method to indicate an external change to any of the entries.
+        """
+        if self.__plugin.getPreferences("AutoSave"):
+            self.saveTrackerEntries()
--- a/TimeTracker/TimeTrackerWidget.py	Sun Oct 21 15:33:36 2012 +0200
+++ b/TimeTracker/TimeTrackerWidget.py	Sun Oct 21 17:03:22 2012 +0200
@@ -10,12 +10,14 @@
 import os
 
 from PyQt4.QtCore import pyqtSlot, QPoint, Qt, QDate, QTime, QFileInfo
-from PyQt4.QtGui import QWidget, QMenu, QTreeWidgetItem, QCursor
+from PyQt4.QtGui import QWidget, QMenu, QTreeWidgetItem, QCursor, QDialog
 
 from E5Gui import E5MessageBox, E5FileDialog
 
 from .Ui_TimeTrackerWidget import Ui_TimeTrackerWidget
 
+from .TimeTrackerEntryDialog import TimeTrackerEntryDialog
+
 import Preferences
 import Utilities
 
@@ -117,6 +119,7 @@
         
         menu.addAction(self.tr("Edit"), self.__editEntry).setEnabled(
             len(self.entriesList.selectedItems()) == 1)
+        menu.addAction(self.tr("Add"), self.__addEntry)
         menu.addAction(self.tr("Delete"), self.__deleteSelectedEntries)
         menu.addSeparator()
         menu.addAction(self.tr("Save"), self.__saveEntries)
@@ -130,12 +133,35 @@
         menu.addAction(self.tr("Merge duplicates"), self.__mergeDuplicates)
         menu.exec_(QCursor.pos())
     
+    def __addEntry(self):
+        """
+        Private slot to manually add an entry.
+        """
+        # TODO: implement this
+    
     def __editEntry(self):
         """
         Private slot to edit the selected tracker entry.
         """
-        # TODO: not implemented yet
-        raise NotImplementedError
+        eid = self.entriesList.selectedItems()[0].data(0, Qt.UserRole)
+        if eid > -1:
+            # the current entry is edited via the elements of this widget
+            entry = self.__tracker.getEntry(eid)
+            if entry is not None:
+                tasks = []
+                for index in range(self.taskCombo.count()):
+                    tasks.append(self.taskCombo.itemText(index))
+                comments = []
+                for index in range(self.commentCombo.count()):
+                    comments.append(self.commentCombo.itemText(index))
+            dlg = TimeTrackerEntryDialog(entry, tasks, comments)
+            if dlg.exec_() == QDialog.Accepted:
+                start, duration, task, comment = dlg.getData()
+                entry.setStartDateTime(start)
+                entry.setDuration(duration)
+                entry.setTask(task)
+                entry.setComment(comment)
+                self.__tracker.entryChanged()
     
     def __deleteSelectedEntries(self):
         """
@@ -279,9 +305,26 @@
         
         @param entries list of tracker entries (list of TimeTrackEntry)
         """
+        self.taskCombo.addItem("")
+        self.commentCombo.addItem("")
+        
+        tasks = []
+        comments = []
+        
         for entry in entries:
             self.__insertEntry(entry)
+            task = entry.getTask()
+            if task and task not in tasks:
+                tasks.append(task)
+            comment = entry.getComment()
+            if comment and comment not in comments:
+                comments.append(comment)
+        
         self.__resizeColumns()
+        if tasks:
+            self.taskCombo.addItems(sorted(tasks))
+        if comments:
+            self.commentCombo.addItems(sorted(comments))
     
     def setCurrentEntry(self, entry):
         """

eric ide

mercurial