author | zautrix <zautrix> | 2005-07-10 20:11:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-10 20:11:56 (UTC) |
commit | f06311e58cb5887fd673eb1c2c48acf7cd987ad9 (patch) (unidiff) | |
tree | 301c74302cdddaa3716d79117023228005ebd265 | |
parent | cb784d21ad22ab72a4e3231974f67816185675fd (diff) | |
download | kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.zip kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.gz kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.bz2 |
smarter faster conflict search
-rw-r--r-- | bin/kdepim/WhatsNew.txt | 1 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 72 | ||||
-rw-r--r-- | libkcal/event.cpp | 20 | ||||
-rw-r--r-- | libkcal/event.h | 1 |
4 files changed, 71 insertions, 23 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt index 1f06f1e..c0d63e5 100644 --- a/bin/kdepim/WhatsNew.txt +++ b/bin/kdepim/WhatsNew.txt | |||
@@ -7,2 +7,3 @@ Added columns for datetime in todo view: Last modified, created and last modifie | |||
7 | Fixed a bug in agenda view displaying recurring multiday events which are longer than two days. | 7 | Fixed a bug in agenda view displaying recurring multiday events which are longer than two days. |
8 | Made conflict detection up to 4 times faster. | ||
8 | 9 | ||
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index a9e402e..427d71b 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -661,3 +661,5 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
661 | { | 661 | { |
662 | 662 | static bool block = false; | |
663 | if ( block ) return; | ||
664 | block = true; | ||
663 | QPtrList<Event> testlist = mCalendar->events(); | 665 | QPtrList<Event> testlist = mCalendar->events(); |
@@ -682,2 +684,4 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
682 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); | 684 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); |
685 | //QTime tm; | ||
686 | //tm.start(); | ||
683 | while ( test ) { | 687 | while ( test ) { |
@@ -687,23 +691,33 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
687 | if ( !skip ) { | 691 | if ( !skip ) { |
692 | if ( found ) | ||
693 | skip = !test->matchTime( &startDT, &conflict ); | ||
694 | else | ||
695 | skip = !test->matchTime( &startDT, 0 ); | ||
696 | } | ||
697 | if ( !skip ) { | ||
688 | Event * test2 = testlist2.first(); | 698 | Event * test2 = testlist2.first(); |
689 | while ( test2 ) { | 699 | while ( test2 ) { |
690 | skip = false; | 700 | skip = test2->isTagged(); |
691 | if ( !all ) skip = ( allday != test2->doesFloat() ); | 701 | if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); |
702 | if ( !skip ) { | ||
703 | if ( found ) | ||
704 | skip = !test2->matchTime( &startDT, &conflict ); | ||
705 | else | ||
706 | skip = !test2->matchTime( &startDT, 0 ); | ||
707 | } | ||
692 | if ( !skip ) { | 708 | if ( !skip ) { |
693 | if ( !test2->isTagged() ) { | 709 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { |
694 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { | 710 | //qDebug("overlap "); |
695 | //qDebug("overlap "); | 711 | if ( ! found ) { |
696 | if ( ! found ) { | 712 | if ( retVal >= startDT ) { |
697 | if ( retVal >= startDT ) { | 713 | conflict = retVal; |
698 | conflict = retVal; | 714 | cE = test; |
699 | cE = test; | 715 | cE2 = test2; |
700 | cE2 = test2; | 716 | found = true; |
701 | found = true; | 717 | } |
702 | } | 718 | } else { |
703 | } else { | 719 | if ( retVal >= startDT && retVal < conflict ) { |
704 | if ( retVal >= startDT && retVal < conflict ) { | 720 | conflict = retVal; |
705 | conflict = retVal; | 721 | cE = test; |
706 | cE = test; | 722 | cE2 = test2; |
707 | cE2 = test2; | ||
708 | } | ||
709 | } | 723 | } |
@@ -718,2 +732,3 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
718 | } | 732 | } |
733 | //qDebug("Search time : %d", tm.elapsed()); | ||
719 | if ( found ) { | 734 | if ( found ) { |
@@ -725,2 +740,3 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
725 | topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); | 740 | topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); |
741 | block = false; | ||
726 | return; | 742 | return; |
@@ -730,2 +746,3 @@ void CalendarView::nextConflict( bool all, bool allday ) | |||
730 | qDebug("No conflict found "); | 746 | qDebug("No conflict found "); |
747 | block = false; | ||
731 | return; | 748 | return; |
@@ -2774,3 +2791,7 @@ void CalendarView::checkConflictForEvent() | |||
2774 | if ( ! mConflictingEvent ) return; | 2791 | if ( ! mConflictingEvent ) return; |
2775 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); | 2792 | QDateTime current = QDateTime::currentDateTime(); |
2793 | if ( ! mConflictingEvent->matchTime( ¤t, 0 ) ) { | ||
2794 | mConflictingEvent = 0; | ||
2795 | return; | ||
2796 | } | ||
2776 | QPtrList<Event> testlist = mCalendar->events(); | 2797 | QPtrList<Event> testlist = mCalendar->events(); |
@@ -2781,6 +2802,11 @@ void CalendarView::checkConflictForEvent() | |||
2781 | Event * cE = 0; | 2802 | Event * cE = 0; |
2782 | QDateTime current = QDateTime::currentDateTime(); | 2803 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); |
2783 | while ( test ) { | 2804 | while ( test ) { |
2784 | qApp->processEvents(); | 2805 | qApp->processEvents(); |
2785 | if ( !test->doesFloat() ) { | 2806 | bool skip = false; |
2807 | if ( found ) | ||
2808 | skip = !test->matchTime( ¤t, &conflict ); | ||
2809 | else | ||
2810 | skip = !test->matchTime( ¤t, 0 ); | ||
2811 | if ( !skip && !test->doesFloat() ) { | ||
2786 | if ( mConflictingEvent->isOverlapping ( test, &retVal, ¤t ) ) { | 2812 | if ( mConflictingEvent->isOverlapping ( test, &retVal, ¤t ) ) { |
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index 5285559..ad66639 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -173,2 +173,22 @@ void Event::setDuration(int seconds) | |||
173 | } | 173 | } |
174 | bool Event::matchTime(QDateTime*startDT, QDateTime* endDT) | ||
175 | { | ||
176 | if ( ! doesRecur() ) { | ||
177 | if ( doesFloat() ) { | ||
178 | if ( mDtEnd.addDays( 1 ) < *startDT) | ||
179 | return false; | ||
180 | if ( endDT && mDtStart > * endDT) | ||
181 | return false; | ||
182 | } else { | ||
183 | if ( mDtEnd < *startDT ) | ||
184 | return false; | ||
185 | if ( endDT && mDtStart > * endDT) | ||
186 | return false; | ||
187 | } | ||
188 | } else { | ||
189 | if ( endDT && mDtStart > * endDT) | ||
190 | return false; | ||
191 | } | ||
192 | return true; | ||
193 | } | ||
174 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) | 194 | bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) |
diff --git a/libkcal/event.h b/libkcal/event.h index e6055a5..2da9770 100644 --- a/libkcal/event.h +++ b/libkcal/event.h | |||
@@ -40,2 +40,3 @@ class Event : public Incidence | |||
40 | ~Event(); | 40 | ~Event(); |
41 | bool matchTime(QDateTime*startDT, QDateTime* endDT); | ||
41 | 42 | ||