From f06311e58cb5887fd673eb1c2c48acf7cd987ad9 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 10 Jul 2005 20:11:56 +0000 Subject: smarter faster conflict search --- (limited to 'korganizer/calendarview.cpp') diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index a9e402e..427d71b 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -659,7 +659,9 @@ CalendarView::~CalendarView() void CalendarView::nextConflict( bool all, bool allday ) { - + static bool block = false; + if ( block ) return; + block = true; QPtrList testlist = mCalendar->events(); Event * test = testlist.first(); while ( test ) { @@ -680,32 +682,44 @@ void CalendarView::nextConflict( bool all, bool allday ) test = testlist.first(); bool skip = false; topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); + //QTime tm; + //tm.start(); while ( test ) { qApp->processEvents(); skip = false; if ( !all ) skip = ( allday != test->doesFloat() ); if ( !skip ) { + if ( found ) + skip = !test->matchTime( &startDT, &conflict ); + else + skip = !test->matchTime( &startDT, 0 ); + } + if ( !skip ) { Event * test2 = testlist2.first(); while ( test2 ) { - skip = false; - if ( !all ) skip = ( allday != test2->doesFloat() ); + skip = test2->isTagged(); + if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); + if ( !skip ) { + if ( found ) + skip = !test2->matchTime( &startDT, &conflict ); + else + skip = !test2->matchTime( &startDT, 0 ); + } if ( !skip ) { - if ( !test2->isTagged() ) { - if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { - //qDebug("overlap "); - if ( ! found ) { - if ( retVal >= startDT ) { - conflict = retVal; - cE = test; - cE2 = test2; - found = true; - } - } else { - if ( retVal >= startDT && retVal < conflict ) { - conflict = retVal; - cE = test; - cE2 = test2; - } + if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { + //qDebug("overlap "); + if ( ! found ) { + if ( retVal >= startDT ) { + conflict = retVal; + cE = test; + cE2 = test2; + found = true; + } + } else { + if ( retVal >= startDT && retVal < conflict ) { + conflict = retVal; + cE = test; + cE2 = test2; } } } @@ -716,6 +730,7 @@ void CalendarView::nextConflict( bool all, bool allday ) test->setTagged( true ); test = testlist.next(); } + //qDebug("Search time : %d", tm.elapsed()); if ( found ) { if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) mViewManager->showDayView(); @@ -723,11 +738,13 @@ void CalendarView::nextConflict( bool all, bool allday ) int hour = conflict.time().hour(); mViewManager->agendaView()->setStartHour( hour ); topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); + block = false; return; } topLevelWidget()->setCaption( i18n("No conflict found") ); qDebug("No conflict found "); + block = false; return; } @@ -2772,17 +2789,26 @@ void CalendarView::checkConflictForEvent() if (!KOPrefs::instance()->mConfirm) return; if ( ! mConflictingEvent ) return; - topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); + QDateTime current = QDateTime::currentDateTime(); + if ( ! mConflictingEvent->matchTime( ¤t, 0 ) ) { + mConflictingEvent = 0; + return; + } QPtrList testlist = mCalendar->events(); Event * test = testlist.first(); QDateTime conflict; QDateTime retVal; bool found = false; Event * cE = 0; - QDateTime current = QDateTime::currentDateTime(); + topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); while ( test ) { - qApp->processEvents(); - if ( !test->doesFloat() ) { + qApp->processEvents(); + bool skip = false; + if ( found ) + skip = !test->matchTime( ¤t, &conflict ); + else + skip = !test->matchTime( ¤t, 0 ); + if ( !skip && !test->doesFloat() ) { if ( mConflictingEvent->isOverlapping ( test, &retVal, ¤t ) ) { if ( ! found ) { conflict = retVal; -- cgit v0.9.0.2