author | zecke <zecke> | 2002-09-25 11:59:24 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-25 11:59:24 (UTC) |
commit | 38240090027bd68d8dd15d7d46ecf17792edb732 (patch) (side-by-side diff) | |
tree | 589ef486d7169c57592ed8667f6c84d43f882d48 | |
parent | 5f2dd0a2340914b4983ebce3813187034e2cb9dc (diff) | |
download | opie-38240090027bd68d8dd15d7d46ecf17792edb732.zip opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.gz opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.bz2 |
Add a sort function and filter function to TodoAccess
This would allow us todo a paint hack in QTable
-rw-r--r-- | libopie/pim/orecordlist.h | 17 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 1 | ||||
-rw-r--r-- | libopie/pim/otodoaccess.cpp | 8 | ||||
-rw-r--r-- | libopie/pim/otodoaccess.h | 16 | ||||
-rw-r--r-- | libopie/pim/otodoaccessbackend.h | 2 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 145 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessbackend.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 145 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 8 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 17 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 1 |
14 files changed, 366 insertions, 16 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index c63d813..1fd0741 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -43,23 +43,23 @@ public: T operator*(); ORecordListIterator &operator++(); ORecordListIterator &operator--(); bool operator==( const ORecordListIterator& it ); bool operator!=( const ORecordListIterator& it ); - + /** * the current item */ uint current()const; - + /** * the number of items */ uint count()const; - + /** * sets the current item */ void setCurrent( uint cur ); private: @@ -98,18 +98,19 @@ public: Iterator begin(); /** * the end */ Iterator end(); - + /** * the number of items in the list */ uint count()const; - + + T operator[]( uint i ); // FIXME implemenent remove /* ConstIterator begin()const; ConstIterator end()const; */ private: @@ -143,13 +144,13 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; m_end = it.m_end; -// m_record = it.m_record; + m_record = it.m_record; return *this; } template <class T> T ORecordListIterator<T>::operator*() { @@ -249,7 +250,11 @@ ORecordList<T>::Iterator ORecordList<T>::end() { return it; } template <class T> uint ORecordList<T>::count()const { return m_ids.count(); } +template <class T> +T ORecordList<T>::operator[]( uint i ) { + return m_acc->find( m_ids[i] ); +} #endif diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index 6dd4c0e..eb9dad3 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp @@ -169,12 +169,13 @@ void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } void OTodo::setPriority(int prio ) { + qWarning("set priority %d", prio); changeOrModify(); data->priority = prio; } void OTodo::setDueDate( QDate date ) { changeOrModify(); diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp index 8ec09bc..f51da29 100644 --- a/libopie/pim/otodoaccess.cpp +++ b/libopie/pim/otodoaccess.cpp @@ -65,7 +65,13 @@ void OTodoAccess::delAlarm( int uid) { // it should be fine -zecke // qWarning("Removing alarm for event with uid %d", uid ); AlarmServer::deleteAlarm( schedule , "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); } - +/* sort order */ +OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { + QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, + filter, cat ); + OTodoAccess::List list( ints, this ); + return list; +} diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h index c43efe9..12997aa 100644 --- a/libopie/pim/otodoaccess.h +++ b/libopie/pim/otodoaccess.h @@ -14,16 +14,23 @@ * the class to get access to * the todolist */ class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { Q_OBJECT public: + enum SortOrder { Completed = 0, + Priority, + Description, + Deadline }; + enum SortFilter{ ShowOverdue = 0, + Category =1, + OnlyOverDue= 2 }; /** * if you use 0l * the default resource will be - * icked up + * picked up */ OTodoAccess( OTodoAccessBackend* = 0l); ~OTodoAccess(); /* our functions here */ @@ -45,12 +52,18 @@ public: /** * return overdue OTodos */ List overDue(); + + /** + * + */ + List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); + /** * merge a list of OTodos into * the resource */ void mergeWith( const QValueList<OTodo>& ); @@ -68,12 +81,13 @@ public: signals: /** * if the OTodoAccess was changed */ void signalChanged( const OTodoAccess* ); private: + int m_cat; OTodoAccessBackend* m_todoBackEnd; class OTodoAccessPrivate; OTodoAccessPrivate* d; }; #endif diff --git a/libopie/pim/otodoaccessbackend.h b/libopie/pim/otodoaccessbackend.h index ebe2189..3bad6b7 100644 --- a/libopie/pim/otodoaccessbackend.h +++ b/libopie/pim/otodoaccessbackend.h @@ -9,10 +9,12 @@ public: OTodoAccessBackend(); ~OTodoAccessBackend(); virtual QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ) = 0; virtual QArray<int> overDue() = 0; + virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, + int cat ) = 0; }; #endif diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 5fe733c..692483e 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp @@ -1,7 +1,8 @@ #include <qfile.h> +#include <qvector.h> #include <qpe/global.h> #include <qpe/stringutil.h> #include <qpe/timeconversion.h> #include <opie/xmltree.h> @@ -253,12 +254,13 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con ev.setDescription( it.data() ); break; case OTodo::Summary: ev.setSummary( it.data() ); break; case OTodo::Priority: + qWarning("ParsePriority " + it.data() ); ev.setPriority( it.data().toInt() ); break; case OTodo::DateDay: day = it.data().toInt(); break; case OTodo::DateMonth: @@ -361,6 +363,149 @@ QString OTodoAccessXML::toString( const OTodo& ev )const { return str; } QString OTodoAccessXML::toString( const QArray<int>& ints ) const { return Qtopia::Record::idsToString( ints ); } + +/* internal class for sorting */ + +struct OTodoXMLContainer { + OTodo todo; +}; + /* + * Returns: + * 0 if item1 == item2 + * + * non-zero if item1 != item2 + * + * This function returns int rather than bool so that reimplementations + * can return one of three values and use it to sort by: + * + * 0 if item1 == item2 + * + * > 0 (positive integer) if item1 > item2 + * + * < 0 (negative integer) if item1 < item2 + * + */ +class OTodoXMLVector : public QVector<OTodoXMLContainer> { +public: + OTodoXMLVector(int size, bool asc, int sort) + : QVector<OTodoXMLContainer>( size ) + { + setAutoDelete( true ); + m_asc = asc; + m_sort = sort; + } + /* return the summary/description */ + QString string( const OTodo& todo) { + return todo.summary().isEmpty() ? + todo.description().left(20 ) : + todo.summary(); + } + /** + * we take the sortorder( switch on it ) + * + */ + int compareItems( Item d1, Item d2 ) { + qWarning("compare items"); + int ret =0; + OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; + OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; + + /* same item */ + if ( con1->todo.uid() == con2->todo.uid() ) + return 0; + qWarning("m_sort %d", m_sort ); + + switch ( m_sort ) { + /* completed */ + case 0: { + ret = 0; + if ( con1->todo.isCompleted() ) ret++; + if ( con2->todo.isCompleted() ) ret--; + break; + } + /* priority */ + case 1: { + ret = con1->todo.priority() - con2->todo.priority(); + qWarning(" priority %d %d %d", ret, + con1->todo.priority(), + con2->todo.priority() + ); + break; + } + /* description */ + case 2: { + QString str1 = string( con1->todo ); + QString str2 = string( con2->todo ); + ret = QString::compare( str1, str2 ); + break; + } + /* deadline */ + case 3: { + /* either bot got a dueDate + * or one of them got one + */ + if ( con1->todo.hasDueDate() && + con2->todo.hasDueDate() ) + ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); + else if ( con1->todo.hasDueDate() ) + ret = -1; + else if ( con2->todo.hasDueDate() ) + ret = 0; + break; + } + default: + ret = 0; + break; + }; + + /* twist it we're not ascending*/ + if (!m_asc) + ret = ret * -1; + return ret; + } + private: + bool m_asc; + int m_sort; + +}; + +QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, + int sortFilter, int cat ) { + OTodoXMLVector vector(m_events.count(), asc,sortOrder ); + QMap<int, OTodo>::Iterator it; + int item = 0; + + bool bCat = sortFilter & 1 ? true : false; + bool bOver = sortFilter & 0 ? true : false; + bool bOnly = split & 2 ? true : false; + for ( it = m_events.begin(); it != m_events.end(); ++it ) { + + /* show category */ + if ( bCat ) + if (!(*it).categories().contains( cat ) ) + continue; + /* isOverdue but we should not show overdue */ + if ( (*it).isOverdue() && ( !bOver || !bOnly ) ) + continue; + if ( !(*it).isOverdue() && bOnly ) + continue; + + + OTodoXMLContainer* con = new OTodoXMLContainer(); + con->todo = (*it); + vector.insert(item, con ); + item++; + } + vector.resize( item ); + /* sort it now */ + vector.sort(); + /* now get the uids */ + QArray<int> array( vector.count() ); + for (uint i= 0; i < vector.count(); i++ ) { + array[i] = ( vector.at(i) )->todo.uid(); + } + return array; +}; diff --git a/libopie/pim/otodoaccessxml.h b/libopie/pim/otodoaccessxml.h index be9109d..6886bab 100644 --- a/libopie/pim/otodoaccessxml.h +++ b/libopie/pim/otodoaccessxml.h @@ -33,12 +33,14 @@ public: /* our functions */ QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ); QArray<int> overDue(); + QArray<int> sorted( bool asc, int sortOrder, + int sortFilter, int cat ); private: OTodo todo( QAsciiDict<int>*, Opie::XMLElement* )const; QString toString( const OTodo& )const; QString toString( const QArray<int>& ints ) const; QMap<int, OTodo> m_events; QString m_file; diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h index ebe2189..3bad6b7 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.h +++ b/libopie2/opiepim/backend/otodoaccessbackend.h @@ -9,10 +9,12 @@ public: OTodoAccessBackend(); ~OTodoAccessBackend(); virtual QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ) = 0; virtual QArray<int> overDue() = 0; + virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, + int cat ) = 0; }; #endif diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 5fe733c..692483e 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp @@ -1,7 +1,8 @@ #include <qfile.h> +#include <qvector.h> #include <qpe/global.h> #include <qpe/stringutil.h> #include <qpe/timeconversion.h> #include <opie/xmltree.h> @@ -253,12 +254,13 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con ev.setDescription( it.data() ); break; case OTodo::Summary: ev.setSummary( it.data() ); break; case OTodo::Priority: + qWarning("ParsePriority " + it.data() ); ev.setPriority( it.data().toInt() ); break; case OTodo::DateDay: day = it.data().toInt(); break; case OTodo::DateMonth: @@ -361,6 +363,149 @@ QString OTodoAccessXML::toString( const OTodo& ev )const { return str; } QString OTodoAccessXML::toString( const QArray<int>& ints ) const { return Qtopia::Record::idsToString( ints ); } + +/* internal class for sorting */ + +struct OTodoXMLContainer { + OTodo todo; +}; + /* + * Returns: + * 0 if item1 == item2 + * + * non-zero if item1 != item2 + * + * This function returns int rather than bool so that reimplementations + * can return one of three values and use it to sort by: + * + * 0 if item1 == item2 + * + * > 0 (positive integer) if item1 > item2 + * + * < 0 (negative integer) if item1 < item2 + * + */ +class OTodoXMLVector : public QVector<OTodoXMLContainer> { +public: + OTodoXMLVector(int size, bool asc, int sort) + : QVector<OTodoXMLContainer>( size ) + { + setAutoDelete( true ); + m_asc = asc; + m_sort = sort; + } + /* return the summary/description */ + QString string( const OTodo& todo) { + return todo.summary().isEmpty() ? + todo.description().left(20 ) : + todo.summary(); + } + /** + * we take the sortorder( switch on it ) + * + */ + int compareItems( Item d1, Item d2 ) { + qWarning("compare items"); + int ret =0; + OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; + OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; + + /* same item */ + if ( con1->todo.uid() == con2->todo.uid() ) + return 0; + qWarning("m_sort %d", m_sort ); + + switch ( m_sort ) { + /* completed */ + case 0: { + ret = 0; + if ( con1->todo.isCompleted() ) ret++; + if ( con2->todo.isCompleted() ) ret--; + break; + } + /* priority */ + case 1: { + ret = con1->todo.priority() - con2->todo.priority(); + qWarning(" priority %d %d %d", ret, + con1->todo.priority(), + con2->todo.priority() + ); + break; + } + /* description */ + case 2: { + QString str1 = string( con1->todo ); + QString str2 = string( con2->todo ); + ret = QString::compare( str1, str2 ); + break; + } + /* deadline */ + case 3: { + /* either bot got a dueDate + * or one of them got one + */ + if ( con1->todo.hasDueDate() && + con2->todo.hasDueDate() ) + ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); + else if ( con1->todo.hasDueDate() ) + ret = -1; + else if ( con2->todo.hasDueDate() ) + ret = 0; + break; + } + default: + ret = 0; + break; + }; + + /* twist it we're not ascending*/ + if (!m_asc) + ret = ret * -1; + return ret; + } + private: + bool m_asc; + int m_sort; + +}; + +QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, + int sortFilter, int cat ) { + OTodoXMLVector vector(m_events.count(), asc,sortOrder ); + QMap<int, OTodo>::Iterator it; + int item = 0; + + bool bCat = sortFilter & 1 ? true : false; + bool bOver = sortFilter & 0 ? true : false; + bool bOnly = split & 2 ? true : false; + for ( it = m_events.begin(); it != m_events.end(); ++it ) { + + /* show category */ + if ( bCat ) + if (!(*it).categories().contains( cat ) ) + continue; + /* isOverdue but we should not show overdue */ + if ( (*it).isOverdue() && ( !bOver || !bOnly ) ) + continue; + if ( !(*it).isOverdue() && bOnly ) + continue; + + + OTodoXMLContainer* con = new OTodoXMLContainer(); + con->todo = (*it); + vector.insert(item, con ); + item++; + } + vector.resize( item ); + /* sort it now */ + vector.sort(); + /* now get the uids */ + QArray<int> array( vector.count() ); + for (uint i= 0; i < vector.count(); i++ ) { + array[i] = ( vector.at(i) )->todo.uid(); + } + return array; +}; diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h index be9109d..6886bab 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.h +++ b/libopie2/opiepim/backend/otodoaccessxml.h @@ -33,12 +33,14 @@ public: /* our functions */ QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ); QArray<int> overDue(); + QArray<int> sorted( bool asc, int sortOrder, + int sortFilter, int cat ); private: OTodo todo( QAsciiDict<int>*, Opie::XMLElement* )const; QString toString( const OTodo& )const; QString toString( const QArray<int>& ints ) const; QMap<int, OTodo> m_events; QString m_file; diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 8ec09bc..f51da29 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp @@ -65,7 +65,13 @@ void OTodoAccess::delAlarm( int uid) { // it should be fine -zecke // qWarning("Removing alarm for event with uid %d", uid ); AlarmServer::deleteAlarm( schedule , "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); } - +/* sort order */ +OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { + QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, + filter, cat ); + OTodoAccess::List list( ints, this ); + return list; +} diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index c43efe9..12997aa 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h @@ -14,16 +14,23 @@ * the class to get access to * the todolist */ class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { Q_OBJECT public: + enum SortOrder { Completed = 0, + Priority, + Description, + Deadline }; + enum SortFilter{ ShowOverdue = 0, + Category =1, + OnlyOverDue= 2 }; /** * if you use 0l * the default resource will be - * icked up + * picked up */ OTodoAccess( OTodoAccessBackend* = 0l); ~OTodoAccess(); /* our functions here */ @@ -45,12 +52,18 @@ public: /** * return overdue OTodos */ List overDue(); + + /** + * + */ + List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); + /** * merge a list of OTodos into * the resource */ void mergeWith( const QValueList<OTodo>& ); @@ -68,12 +81,13 @@ public: signals: /** * if the OTodoAccess was changed */ void signalChanged( const OTodoAccess* ); private: + int m_cat; OTodoAccessBackend* m_todoBackEnd; class OTodoAccessPrivate; OTodoAccessPrivate* d; }; #endif diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index c63d813..1fd0741 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h @@ -43,23 +43,23 @@ public: T operator*(); ORecordListIterator &operator++(); ORecordListIterator &operator--(); bool operator==( const ORecordListIterator& it ); bool operator!=( const ORecordListIterator& it ); - + /** * the current item */ uint current()const; - + /** * the number of items */ uint count()const; - + /** * sets the current item */ void setCurrent( uint cur ); private: @@ -98,18 +98,19 @@ public: Iterator begin(); /** * the end */ Iterator end(); - + /** * the number of items in the list */ uint count()const; - + + T operator[]( uint i ); // FIXME implemenent remove /* ConstIterator begin()const; ConstIterator end()const; */ private: @@ -143,13 +144,13 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; m_end = it.m_end; -// m_record = it.m_record; + m_record = it.m_record; return *this; } template <class T> T ORecordListIterator<T>::operator*() { @@ -249,7 +250,11 @@ ORecordList<T>::Iterator ORecordList<T>::end() { return it; } template <class T> uint ORecordList<T>::count()const { return m_ids.count(); } +template <class T> +T ORecordList<T>::operator[]( uint i ) { + return m_acc->find( m_ids[i] ); +} #endif diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index 6dd4c0e..eb9dad3 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp @@ -169,12 +169,13 @@ void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } void OTodo::setPriority(int prio ) { + qWarning("set priority %d", prio); changeOrModify(); data->priority = prio; } void OTodo::setDueDate( QDate date ) { changeOrModify(); |