Ejemplo n.º 1
0
void KateSessionManager::updateSessionList()
{
    m_sessionList.clear();

    // Let's get a list of all session we have atm
    QDir dir(m_sessionsDir, "*.katesession");

    bool foundDefault = false;
    for(unsigned int i = 0; i < dir.count(); ++i)
    {
        KateSession *session = new KateSession(this, dir[i], "");
        m_sessionList.append(session);

        kdDebug() << "FOUND SESSION: " << session->sessionName() << " FILE: " << session->sessionFile() << endl;

        if(!foundDefault && (dir[i] == "default.katesession"))
            foundDefault = true;
    }

    // add default session, if not there
    if(!foundDefault)
        m_sessionList.append(new KateSession(this, "default.katesession", i18n("Default Session")));

    qHeapSort(m_sessionList);
}
Ejemplo n.º 2
0
KNumber KStats::median(void) {

	KNumber result = 0;
	unsigned int bound;
	size_t index;

	bound = count();

	if (bound == 0){
		error_flag = true;
		return 0;
	}

	if (bound == 1)
		return mData.at(0);

	// need to copy mData-list, because sorting afterwards
	TQValueVector<KNumber> tmp_mData(mData);
	qHeapSort(tmp_mData);

	if( bound & 1) {  // odd
		index = (bound - 1 ) / 2 + 1;
		result =  tmp_mData.at(index - 1);
	} else { // even
	  index = bound / 2;
	  result = ((tmp_mData.at(index - 1))  + (tmp_mData.at(index))) / KNumber(2);
	}

	return result;
}
Ejemplo n.º 3
0
//#### Why is this code duplicated in getEffectiveEvents ?????
//#### Addendum.  Don't use this function, lets faze it out if we can.
QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to )
{
    QValueList<Event> tmpList;
    tmpList = getNonRepeatingEvents( from, to );

    // check for repeating events...
    for (QValueList<Event>::ConstIterator it = repeatEvents.begin();
         it != repeatEvents.end(); ++it) {
        QDate itDate = from;
        QDateTime due;

        /* create a false end date, to short circuit on hard
           MonthlyDay recurences */
        Event dummy_event = *it;
        Event::RepeatPattern r = dummy_event.repeatPattern();
        if ( !r.hasEndDate || r.endDate() > to ) {
            r.setEndDate( to );
            r.hasEndDate = TRUE;
        }
        dummy_event.setRepeat(TRUE, r);

        while (nextOccurance(dummy_event, itDate, due)) {
            if (due.date() > to)
                break;
            Event newEvent = *it;
            newEvent.setStart(due);
            newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end())));

            tmpList.append(newEvent);
            itDate = due.date().addDays(1);  /* the next event */
        }
    }
    qHeapSort(tmpList);
    return tmpList;
}
Ejemplo n.º 4
0
void PanelRemoveButtonMenu::slotAboutToShow()
{
    clear();
    containers.clear();

    addToContainers("URLButton");
    addToContainers("ServiceButton");
    addToContainers("ServiceMenuButton");
    addToContainers("ExecButton");

    int id = 0;
    QValueList<PanelMenuItemInfo> items;
    for (BaseContainer::Iterator it = containers.begin(); it != containers.end(); ++it)
    {
        items.append(PanelMenuItemInfo((*it)->icon(), (*it)->visibleName(), id));
        id++;
    }

    qHeapSort(items);

    for (QValueList<PanelMenuItemInfo>::iterator it = items.begin();
         it != items.end();
         ++it)
    {
        (*it).plug(this);
    }

    if (containers.count() > 1)
    {
        insertSeparator();
        insertItem(i18n("All"), this, SLOT(slotRemoveAll()), 0, id);
    }
}
Ejemplo n.º 5
0
void MyMoneyReport::validDateRange ( QDate& _db, QDate& _de )
{
  _db = fromDate();
  _de = toDate();

  // if either begin or end date are invalid we have one of the following
  // possible date filters:
  //
  // a) begin date not set - first transaction until given end date
  // b) end date not set   - from given date until last transaction
  // c) both not set       - first transaction until last transaction
  //
  // If there is no transaction in the engine at all, we use the current
  // year as the filter criteria.

  if ( !_db.isValid() || !_de.isValid() ) {
    QValueList<MyMoneyTransaction> list = MyMoneyFile::instance()->transactionList ( *this );
    QDate tmpBegin, tmpEnd;

    if ( !list.isEmpty() ) {
      qHeapSort ( list );
      tmpBegin = list.front().postDate();
      tmpEnd = list.back().postDate();
    } else {
      tmpBegin = QDate ( QDate::currentDate().year(), 1, 1 ); // the first date in the file
      tmpEnd = QDate ( QDate::currentDate().year(), 12, 31 );// the last date in the file
    }
    if ( !_db.isValid() )
      _db = tmpBegin;
    if ( !_de.isValid() )
      _de = tmpEnd;
  }
  if ( _db > _de )
    _db = _de;
}
Ejemplo n.º 6
0
void KoZoomAction::setZoom( const QString& text )
{
  bool ok = false;
  QString t = text;
  int zoom = t.remove( '%' ).toInt( &ok );
  
  // where we'll store sorted new zoom values
  QValueList<int> list;
  if( zoom > 10 ) list.append( zoom );
  
  // "Captured" non-empty sequence of digits
  QRegExp regexp("(\\d+)"); 
  
  const QStringList itemsList( items() );
  for( QStringList::ConstIterator it = itemsList.begin(); it != itemsList.end(); ++it )
  {
    regexp.search( *it );
    const int val=regexp.cap(1).toInt( &ok );
    
    //zoom : limit inferior=10
    if( ok && val>9 && list.contains( val )==0 )
      list.append( val );
  }
  
  qHeapSort( list );

  // update items with new sorted zoom values
  QStringList values;
  for (QValueList<int>::Iterator it = list.begin(); it != list.end(); ++it )
    values.append( i18n("%1%").arg(*it) );
  setItems( values );
  
  QString zoomStr = i18n("%1%").arg( zoom );
  setCurrentItem( values.findIndex( zoomStr ) );
}
Ejemplo n.º 7
0
/**
 * \brief Return only the enabled plugins
 * Return only activated plugins.
 *
 * @param sorted If the list should be sorted
 */
OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const {
    OPluginItem::List lst;
    for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
        lst += plugins(  *it, sorted, true );

    if ( sorted )
        qHeapSort( lst );
    return lst;
}
Ejemplo n.º 8
0
void KWDocStructRootItem::setupTextFrameSets()
{

    // Delete Empty item from list.
    QListViewItem* lvItem = firstChild();
    if (lvItem && (lvItem->text(0) == i18n("Empty"))) delete lvItem;

    // Build a list of framesets ordered by their screen position (top left corner).
    KWDocument* dok = doc();
    QValueList<KWOrderedFrameSet> orderedFrameSets;
    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) {
        KWFrameSet* frameset = dok->frameSet(i);
        if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY &&
            !frameset->groupmanager() && frameset->frameCount()>0)

            orderedFrameSets.append(KWOrderedFrameSet(frameset));
    }
    qHeapSort(orderedFrameSets);

    // Build a list of frameset pointers from the sorted list.
    QPtrList<KWTextFrameSet> frameSetPtrs;
    frameSetPtrs.setAutoDelete(false);
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
        frameSetPtrs.append(dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet()));

    // Remove deleted framesets from the listview.
    KWDocStructTextFrameSetItem* item = dynamic_cast<KWDocStructTextFrameSetItem *>(firstChild());
    KWDocStructTextFrameSetItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructTextFrameSetItem *>(item->nextSibling());
        if (frameSetPtrs.containsRef(delItem->frameSet()) == 0) delete delItem;
    }

    // Add new framesets to the list or update existing ones.
    KWDocStructTextFrameSetItem* after = 0L;
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
    {
        KWTextFrameSet* textFrameset = dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet());
        item = findTextFrameSetItem(textFrameset);
        if (item)
            item->setText(0, textFrameset->name());
        else {
            if (after)
                item = new KWDocStructTextFrameSetItem(
                    this, after, textFrameset->name(), textFrameset);
            else
                item = new KWDocStructTextFrameSetItem(this, textFrameset->name(), textFrameset);
        }
        after = item;
        item->setupTextFrames();
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Ejemplo n.º 9
0
OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
                                                                    const QDate& to ) {
    OEffectiveEvent::ValueList tmpList;
    OEvent::ValueList list = directNonRepeats();

    events( tmpList, list, from, to );

    qHeapSort( tmpList );
    return tmpList;
}
Ejemplo n.º 10
0
OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from,
                                                                    const QDate& to ) {
    OEffectiveEvent::ValueList tmpList;
    OEvent::ValueList list = directNonRepeats();

    events( tmpList, list, from, to );
    repeat( tmpList, directRawRepeats(),from,to );

    list = directRawRepeats();  // Useless, isn't it ? (eilers)

    qHeapSort( tmpList );
    return tmpList;
}
Ejemplo n.º 11
0
QValueList<StringPair> KLocaleConfigTime::timeMap() const
{
  QValueList < StringPair > list;
  list+=buildStringPair('H',m_locale->translate("HH"));
  list+=buildStringPair('k',m_locale->translate("hH"));
  list+=buildStringPair('I',m_locale->translate("PH"));
  list+=buildStringPair('l',m_locale->translate("pH"));
  list+=buildStringPair('M',m_locale->translate("Minute", "MM"));
  list+=buildStringPair('S',m_locale->translate("SS"));
  list+=buildStringPair('p',m_locale->translate("AMPM"));

  qHeapSort( list );

  return list;
}
Ejemplo n.º 12
0
void JumpButtonBar::sortListLocaleAware( QStringList &list )
{
  QValueList<SortContainer> sortList;

  QStringList::ConstIterator it;
  for ( it = list.begin(); it != list.end(); ++it )
    sortList.append( SortContainer( *it ) );

  qHeapSort( sortList );
  list.clear();

  QValueList<SortContainer>::ConstIterator sortIt;
  for ( sortIt = sortList.begin(); sortIt != sortList.end(); ++sortIt )
    list.append( (*sortIt).data() );
}
Ejemplo n.º 13
0
void MapLoader::load(unsigned int width, const QString &theme, unsigned int height, float opacity)
{
  // find the maps available
  QValueList<uint> sizes;
  QStringList files = maps(theme);
  for (uint i=0; i<files.count(); ++i)
    {
      QString f = files[i];
      int pos = f.findRev("/");
      if (pos >= 0)
        f = f.mid(pos+1);
      pos = f.findRev(".");
      if (pos >= 0)
        f = f.left(pos);
      sizes.append(f.toInt());
    }
  qHeapSort(sizes);

  // find the closest (bigger) size
  uint size=0;
  for (uint i=0; i<sizes.count(); ++i)
    if (sizes[i] >= width)
      {
	size = sizes[i];
	break;
      }
  
  QImage image;
  if (size == 0)
    {
      image = QImage(locate("data", "kworldclock/maps/depths/800.jpg"));
      size = 800;
    }
  else  
    image = QImage(locate("data", QString("kworldclock/maps/%1/%2.jpg").arg(theme).arg(size)));

  if (height == 0)
    height = width/2;

  if ((image.width() != (int)width) || (image.height() != (int)height))
    image = image.smoothScale(width, height);

  // convert to light map
  _light.convertFromImage(image);

  // calculate dark map
  _dark.convertFromImage(KImageEffect::blend(Qt::black, image, opacity));
}
Ejemplo n.º 14
0
QStringList AddressEditDialog::sortLocaleAware( const QStringList &list )
{
  QValueList<LocaleAwareString> sortedList;

  QStringList::ConstIterator it;
  for ( it = list.begin(); it != list.end(); ++it )
    sortedList.append( LocaleAwareString( *it ) );

  qHeapSort( sortedList );

  QStringList retval;
  QValueList<LocaleAwareString>::ConstIterator retIt;
  for ( retIt = sortedList.begin(); retIt != sortedList.end(); ++retIt )
    retval.append( *retIt );

  return retval;
}
Ejemplo n.º 15
0
void PluginFactory::createGUIs()
{
    //sort GUI plugins according to significance
    qHeapSort(d->guiPlugins);

    for( PluginFactoryPrivate::GuiPluginList::iterator it = d->guiPlugins.begin(); it != d->guiPlugins.end(); ++it ) {
        Plugin *plugin = (*it).plugin();
        if( !plugin ) continue;

        PTRACE( 1, "Creating GUI of plugin " << plugin->name() );
        QWidget *widget = plugin->createGUI();
        if ( widget ) {
            emit insertWidget( widget, plugin->type(), plugin->text(), plugin->icon(), plugin->significance(), plugin->guiType() );
            insertedWidgets[plugin->pluginInfo()->id] = widget;
        } else
            PTRACE( 1, "Failed" );
    }
}
Ejemplo n.º 16
0
QValueList <StringPair> KLocaleConfigTime::dateMap() const
{
  QValueList < StringPair > list;
  list+=buildStringPair('Y',m_locale->translate("YYYY"));
  list+=buildStringPair('y',m_locale->translate("YY"));
  list+=buildStringPair('n',m_locale->translate("mM"));
  list+=buildStringPair('m',m_locale->translate("Month", "MM"));
  list+=buildStringPair('b',m_locale->translate("SHORTMONTH"));
  list+=buildStringPair('B',m_locale->translate("MONTH"));
  list+=buildStringPair('e',m_locale->translate("dD"));
  list+=buildStringPair('d',m_locale->translate("DD"));
  list+=buildStringPair('a',m_locale->translate("SHORTWEEKDAY"));
  list+=buildStringPair('A',m_locale->translate("WEEKDAY"));

  qHeapSort( list );

  return list;
}
Ejemplo n.º 17
0
QValueList<int> Navigator::functionStartLines()
{
    FileDom file = m_part->codeModel()->fileByName ( m_part->m_activeFileName );
    if ( !file ) return QValueList<int>();

    QValueList<int> lines;
    FunctionDefinitionList list = CodeModelUtils::allFunctionDefinitionsExhaustive ( file );
    FunctionDefinitionList::const_iterator it = list.begin();
    while ( it != list.end() )
    {
        int line, col;
        ( *it )->getStartPosition ( &line, &col );
        lines << line;
        ++it;
    }
    qHeapSort ( lines );

    return lines;
}
Ejemplo n.º 18
0
void PanelRemoveAppletMenu::slotAboutToShow()
{
    int id = 0;

    clear();
    m_containers = m_containerArea->containers("Applet") +
                   m_containerArea->containers("Special Button");

    QValueList<PanelMenuItemInfo> items;

    for (BaseContainer::List::const_iterator it = m_containers.constBegin();
         it != m_containers.constEnd();)
    {
        BaseContainer* container = *it;
        if (container->isImmutable())
        {
            ++it;
            m_containers.remove(container);
            continue;
        }

        items.append(PanelMenuItemInfo(container->icon(),
                                       container->visibleName().replace("&", "&&"),
                                       id));
        ++id;
        ++it;
    }

    qHeapSort(items);

    for (QValueList<PanelMenuItemInfo>::iterator it = items.begin();
         it != items.end();
         ++it)
    {
        (*it).plug(this);
    }

    if (m_containers.count() > 1)
    {
        insertSeparator();
        insertItem(i18n("All"), this, SLOT(slotRemoveAll()), 0, id);
    }
}
Ejemplo n.º 19
0
void LapsusPanelMain::showContextMenu()
{
	_popMenu = new KPopupMenu( this );
	_popMenu->insertTitle( SmallIcon( "laptop" ), i18n("Switches") );

	KActionPtrList list = _actions->actions();
	qHeapSort( list );

	if (list.size() > 0)
	{
		for(KActionPtrList::iterator it = list.begin(); it != list.end(); ++it)
		{
			(*it)->plug(_popMenu);
		}
	}

	QPoint pos = QCursor::pos();
	_popMenu->popup( pos );
}
Ejemplo n.º 20
0
// Construct a list of keys to be connected, sorted highest priority first.
void KAccelBase::createKeyList(QValueVector< struct X > &rgKeys)
{
    // kdDebug(125) << "KAccelBase::createKeyList()" << endl;
    if(!isEnabledInternal())
        return;

    // create the list
    // For each action
    for(uint iAction = 0; iAction < m_rgActions.count(); iAction++)
    {
        KAccelAction *pAction = m_rgActions.actionPtr(iAction);
        if(pAction && pAction->m_pObjSlot && pAction->m_psMethodSlot && pAction != mtemp_pActionRemoving)
        {
            // For each key sequence associated with action
            for(uint iSeq = 0; iSeq < pAction->shortcut().count(); iSeq++)
            {
                const KKeySequence &seq = pAction->shortcut().seq(iSeq);
                if(seq.count() > 0)
                {
                    KKeyServer::Variations vars;
                    vars.init(seq.key(0), !m_bNativeKeys);
                    for(uint iVari = 0; iVari < vars.count(); iVari++)
                    {
                        if(vars.key(iVari).code() && vars.key(iVari).sym())
                            rgKeys.push_back(X(iAction, iSeq, iVari, vars.key(iVari)));
                        // kdDebug(125) << "\t" << pAction->name() << ": " << vars.key(iVari).toStringInternal() << endl;
                    }
                }
                // else
                //	kdDebug(125) << "\t*" << pAction->name() << ":" << endl;
            }
        }
    }

    // sort by priority: iVariation[of first key], iSequence, iAction
    qHeapSort(rgKeys.begin(), rgKeys.end());
}
Ejemplo n.º 21
0
PluginInfoList& PluginFactory::rescan()
{
    //remove plugins that are not loaded

    PluginInfoList::Iterator it = infoList.begin();
    while( it != infoList.end() ) {
        PluginInfo *info = (*it).first;
        if( !info ) continue;

        //plugin is not loaded
        if( !info->get() ) {
            QLibrary *lib = (*it).second;
            lib->unload();
            delete lib;
            it = infoList.remove(it);
            continue;
        }
        ++it;
    }

    //load all plugins (and avoid collisions)

    QRegExp libRxp = QRegExp( "^lib.*\\.so[0-9.]*$" );
    //QRegExp libRxp = QRegExp( "^lib.*" );

    PluginInfoList pluginList;

    QStringList libraryPaths = ancaConf->readListEntry( LIBRARY_PATHS, LIBRARY_PATHS_DEFAULT );
#ifdef PREL
    libraryPaths.append( PREL "/share/anca/plugins");
#endif
    libraryPaths.append(QDir::homeDirPath() + "/.anca/plugins");

    //iterate all paths where plugins should be
    for ( QStringList::iterator it = libraryPaths.begin(); it != libraryPaths.end(); ++it ) {
        PTRACE( 3, "Searching directory " << ( *it ).latin1() << " for plugins" );
        QDir dir( *it );
        if ( !dir.exists() ) continue;

        dir.setFilter( QDir::Files | QDir::NoSymLinks );

        const QFileInfoList *fileList = dir.entryInfoList();
        QFileInfo *file;
        QLibrary *lib;
        //iterate all files in the directory
        for ( QFileInfoListIterator fit( *fileList ); ( file = *fit ); ++fit ) {
            //is the file plugin?
            if ( !file->fileName().contains( libRxp ) ) continue;

            //open plugin
            lib = new QLibrary( file->filePath().latin1() );

            if( !lib->load() ) {
                PTRACE( 3, "Library " << file->fileName().latin1() << " could not be loaded" );
                continue;
            }

            //resolve symbol 'getPluginInfo'
            if ( GetPluginInfo * getPluginInfo = ( GetPluginInfo* ) lib->resolve( "getPluginInfo" ) ) {
                PluginInfo * pluginInfo = getPluginInfo();

                pluginList.append( PluginInfoPair(pluginInfo, lib) );
            } else {
                PTRACE( 3, "Symbol \"getPluginInfo\" not found in library " << file->fileName().latin1() );
                delete lib;
            }
        }
    }

    //insert that pluginInfo to class infoList that in not already there
    for( PluginInfoList::iterator it = pluginList.begin(); it != pluginList.end(); ++it ) {
        QLibrary *lib = (*it).second;
        if( !lib ) continue;

        if( !infoList.contains( *it ) )
            infoList.append( *it );
        else {
            lib->unload();
            delete lib;
        }
    }

    // sort plugins according to type
    qHeapSort(infoList);

    return infoList;
}
Ejemplo n.º 22
0
/*!
  Sorts the list of strings in ascending order.

  Sorting is very fast. It uses the Qt Template Library's
  efficient HeapSort implementation that operates in O(n*log n).
*/
void QStringList::sort()
{
    qHeapSort(*this);
}
bool UpdateThread::doUpdates(bool force, bool *gotData) {
  KstObject::UpdateType U = KstObject::NO_CHANGE;

  _updatedCurves.clear(); // HACK

  if (gotData) {
    *gotData = false;
  }
  
#if UPDATEDEBUG > 0
  if (force) {
    kstdDebug() << "Forced update!" << endl;
  }
#endif

  _updateCounter++;
  if (_updateCounter < 1) {
    _updateCounter = 1; // check for wrap around
  }

#if UPDATEDEBUG > 2
  kstdDebug() << "UPDATE: counter=" << _updateCounter << endl;
#endif

  {
    // Must make a copy to avoid deadlock
    KstBaseCurveList cl;
    KstDataObjectList dol;
    kstObjectSplitList<KstDataObject, KstBaseCurve>(KST::dataObjectList, cl, dol);
    qHeapSort(cl); 
    qHeapSort(dol); 

    // Update all curves
    for (uint i = 0; i < cl.count(); ++i) {
      KstBaseCurvePtr bcp = cl[i];
      bcp->writeLock();
      assert(bcp.data());
#if UPDATEDEBUG > 1
      kstdDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
      KstObject::UpdateType ut = bcp->update(_updateCounter);
      bcp->unlock();

      if (ut == KstObject::UPDATE) { // HACK
        _updatedCurves.append(bcp);
      }

      if (U != KstObject::UPDATE) {
        U = ut;
        if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
          kstdDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
        }
      }

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        kstdDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }

    // Update all data objects
    for (uint i = 0; i < dol.count(); ++i) {
      KstDataObjectPtr dp = dol[i];
      dp->writeLock();
      assert(dp.data());
#if UPDATEDEBUG > 1
      kstdDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
      dp->update(_updateCounter);
      dp->unlock();

      if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
        kstdDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
        return U == KstObject::UPDATE;
      }
    }
  }

  // Update the files
  if (!_paused) { // don't update even if paused && force
    KST::dataSourceList.lock().readLock();
    unsigned cnt = KST::dataSourceList.count();
    for (uint i = 0; i < cnt; ++i) {
      KstDataSourcePtr dsp = KST::dataSourceList[i];

      dsp->writeLock();
      dsp->update(_updateCounter);
      dsp->unlock();

      if (_done) {
        KST::dataSourceList.lock().unlock();
        return false;
      }
    }
    KST::dataSourceList.lock().unlock();
  }

  if (KstScalar::scalarsDirty()) {
    KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
                                    // falling slightly behind
    KST::scalarList.lock().readLock();
    KstScalarList sl = QDeepCopy<KstScalarList>(KST::scalarList.list()); // avoid deadlock on exit
    KST::scalarList.lock().unlock();
    for (KstScalarList::ConstIterator i = sl.begin(); i != sl.end(); ++i) {
      KstScalarPtr sp = *i;

      sp->writeLock();
      KstObject::UpdateType ut = sp->update(_updateCounter);
      sp->unlock();

      if (ut == KstObject::UPDATE) {
        U = KstObject::UPDATE;
      }

      if (_done) {
        return false;
      }
    }
  }

  if (U == KstObject::UPDATE) {
    kstdDebug() << "Update plots" << endl;
    if (gotData) { // FIXME: do we need to consider all the other exit points?
      *gotData = true;
    }
  }

#if UPDATEDEBUG > 1
  kstdDebug() << "6 Returning from scan with U=" << (int)U << endl;
#endif
  return U == KstObject::UPDATE;
}
Ejemplo n.º 24
0
QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from,
                                                           const QDate &to )
{
    QValueList<EffectiveEvent> tmpList;
    QValueListIterator<Event> it;

    EffectiveEvent effEv;
    QDateTime dtTmp,
              dtEnd;

    for (it = eventList.begin(); it != eventList.end(); ++it ) {
        if (!(*it).isValidUid())
            (*it).assignUid(); // FIXME: Hack to restore cleared uids

        dtTmp = (*it).start(TRUE);
        dtEnd = (*it).end(TRUE);

        if ( dtTmp.date() >= from && dtTmp.date() <= to ) {
            Event tmpEv = *it;
            effEv.setEvent(tmpEv);
            effEv.setDate( dtTmp.date() );
            effEv.setStart( dtTmp.time() );
            if ( dtTmp.date() != dtEnd.date() )
                effEv.setEnd( QTime(23, 59, 0) );
            else
                effEv.setEnd( dtEnd.time() );
            tmpList.append( effEv );
        }
        // we must also check for end date information...
        if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) {
            QDateTime dt = dtTmp.addDays( 1 );
            dt.setTime( QTime(0, 0, 0) );
            QDateTime dtStop;
            if ( dtEnd > to ) {
                dtStop = to;
            } else
                dtStop = dtEnd;
            while ( dt <= dtStop ) {
                Event tmpEv = *it;
                effEv.setEvent( tmpEv );
                effEv.setDate( dt.date() );
                if ( dt >= from ) {
                    effEv.setStart( QTime(0, 0, 0) );
                    if ( dt.date() == dtEnd.date() )
                        effEv.setEnd( dtEnd.time() );
                    else
                        effEv.setEnd( QTime(23, 59, 59) );
                    tmpList.append( effEv );
                }
                dt = dt.addDays( 1 );
            }
        }
    }
    // check for repeating events...
    QDateTime repeat;
    for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) {
        if (!(*it).isValidUid())
            (*it).assignUid(); // FIXME: Hack to restore cleared uids

        /* create a false end date, to short circuit on hard
           MonthlyDay recurences */
        Event dummy_event = *it;
        int duration = (*it).start().date().daysTo( (*it).end().date() );
        QDate itDate = from.addDays(-duration);

        Event::RepeatPattern r = dummy_event.repeatPattern();
        if ( !r.hasEndDate || r.endDate() > to ) {
            r.setEndDate( to );
            r.hasEndDate = TRUE;
        }
        dummy_event.setRepeat(TRUE, r);

        while (nextOccurance(dummy_event, itDate, repeat)) {
            if(repeat.date() > to)
                break;
            effEv.setDate( repeat.date() );
            if ((*it).type() == Event::AllDay) {
                effEv.setStart( QTime(0,0,0) );
                effEv.setEnd( QTime(23,59,59) );
            } else {
                /* we only occur by days, not hours/minutes/seconds.  Hence
                   the actual end and start times will be the same for
                   every repeated event.  For multi day events this is
                   fixed up later if on wronge day span */
                effEv.setStart( (*it).start().time() );
                effEv.setEnd( (*it).end().time() );
            }
            if ( duration != 0 ) {
                // multi-day repeating events
                QDate sub_it = QMAX( repeat.date(), from );
                QDate startDate = repeat.date();
                QDate endDate = startDate.addDays( duration );

                while ( sub_it <= endDate && sub_it  <= to ) {
                    EffectiveEvent tmpEffEv = effEv;
                    Event tmpEv = *it;
                    tmpEffEv.setEvent( tmpEv );

                    if ( sub_it != startDate )
                        tmpEffEv.setStart( QTime(0,0,0) );
                    if ( sub_it != endDate )
                        tmpEffEv.setEnd( QTime(23,59,59) );
                    tmpEffEv.setDate( sub_it );
                    tmpEffEv.setEffectiveDates( startDate, endDate );
                    tmpList.append( tmpEffEv );
                    sub_it = sub_it.addDays( 1 );
                }
                itDate = endDate;
            } else {
                Event tmpEv = *it;
                effEv.setEvent( tmpEv );
                tmpList.append( effEv );
                itDate = repeat.date().addDays( 1 );
            }
        }
    }

    qHeapSort( tmpList );
    return tmpList;
}
Ejemplo n.º 25
0
void KKbdAccessExtensions::displayAccessKeys()
{
    // Build a list of valid access keys that don't collide with shortcuts.
    QString availableAccessKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
    QPtrList<KXMLGUIClient> allClients = d->mainWindow->factory()->clients();
    QPtrListIterator<KXMLGUIClient> it( allClients );
    KXMLGUIClient *client;
    while( (client=it.current()) !=0 )
    {
        ++it;
        KActionPtrList actions = client->actionCollection()->actions();
        for (int j = 0; j < (int)actions.count(); j++) {
            KAction* action = actions[j];
            KShortcut sc = action->shortcut();
            for (int i = 0; i < (int)sc.count(); i++) {
                KKeySequence seq = sc.seq(i);
                if (seq.count() == 1) {
                    QString s = seq.toString();
                    if (availableAccessKeys.contains(s))
                        availableAccessKeys.remove(s);
                }
            }
        }
    }
    // Find all visible, focusable widgets and create a QLabel for each.  Don't exceed
    // available list of access keys.
    QWidgetList* allWidgets = kapp->allWidgets();
    QWidget* widget = allWidgets->first();
    int accessCount = 0;
    int maxAccessCount = availableAccessKeys.length();
    int overlap = 20;
    QPoint prevGlobalPos = QPoint(-overlap, -overlap);
    while (widget && (accessCount < maxAccessCount)) {
        if (widget->isVisible() && widget->isFocusEnabled() ) {
            QRect r = widget->rect();
            QPoint p(r.x(), r.y());
            // Don't display an access key if within overlap pixels of previous one.
            QPoint globalPos = widget->mapToGlobal(p);
            QPoint diffPos = globalPos - prevGlobalPos;
            if (diffPos.manhattanLength() > overlap) {
                accessCount++;
                QLabel* lab=new QLabel(widget, "", widget, 0, Qt::WDestructiveClose);
                lab->setPalette(QToolTip::palette());
                lab->setLineWidth(2);
                lab->setFrameStyle(QFrame::Box | QFrame::Plain);
                lab->setMargin(3);
                lab->adjustSize();
                lab->move(p);
                if (!d->accessKeyLabels) {
                    d->accessKeyLabels = new QPtrList<QLabel>;
                    d->accessKeyLabels->setAutoDelete(true);
                }
                d->accessKeyLabels->append(lab);
                prevGlobalPos = globalPos;
            }
        }
        widget = allWidgets->next();
    }
    if (accessCount > 0) {
        // Sort the access keys from left to right and down the screen.
        QValueList<KSortedLabel> sortedLabels;
        for (int i = 0; i < accessCount; i++)
            sortedLabels.append(KSortedLabel(d->accessKeyLabels->at(i)));
        qHeapSort( sortedLabels );
        // Assign access key labels.
        for (int i = 0; i < accessCount; i++) {
            QLabel* lab = sortedLabels[i].label();
            QChar s = availableAccessKeys[i];
            lab->setText(s);
            lab->adjustSize();
            lab->show();
        }
    }
}
Ejemplo n.º 26
0
int
SMatrix::createFormula(void) {
  bool *AVector;
  bool *BVector;
  int FormA, FormB, FormC, FormD;
  int count0, count1, count2, count3;
  int ChangeA, ChangeB;
  std::complex<double> A,B,C,D;
  int Row, Column;
  std::complex<double> Null_(0.0,0.0);
  std::complex<double> One_(1.0,0.0);

  if (FormulaExists_) return Formula.List.count();

  fillMatrix(500e6);

#ifdef DEBUG_
  std::cout << print();
#endif

  count0=count1=count2=count3=0;

  AVector = (bool*) calloc(MatrixDimension_, sizeof(bool));
  BVector = (bool*) calloc(MatrixDimension_, sizeof(bool));
  for (int i=0; i<MatrixDimension_; i++) {
   *(AVector+i)=false;
   *(BVector+i)=false;
  }

  qHeapSort( ChopUp.List);
#ifdef DEBUG_
  std::cout << ChopUp.print() << std::endl;
  std::cout << "MatrixDimension: " << MatrixDimension_ << std::endl;
#endif

  QValueList<ChopUpElement>::Iterator it;
  for ( it = ChopUp.List.begin(); it != ChopUp.List.end(); it++ ) {
    ChangeA = (*it).a()-1;
    ChangeB = (*it).b()-1;
    FormD = MatrixDimension_*ChangeB + ChangeA;
    D = *(SMatrix_+FormD);
    Row=0;
    while (Row < MatrixDimension_) {
     while ( ( (*(BVector+Row)) && (Row<MatrixDimension_) ) || (Row==ChangeB) ) Row++;
     if (Row<MatrixDimension_) {
      FormB=MatrixDimension_*Row+ChangeA;
      B = *(SMatrix_+FormB);
      if (B != Null_) {
       Column=0;
       while (Column < MatrixDimension_) {
        while ( ( (*(AVector+Column)) && (Column<MatrixDimension_) ) || (Column==ChangeA) ) Column++;
        if (Column<MatrixDimension_) {
         FormC = MatrixDimension_*ChangeB + Column;
         C = *(SMatrix_+FormC);
         if (C != Null_) {
          FormA = MatrixDimension_*Row + Column;
          A = *(SMatrix_ + FormA);
#ifdef DEBUG_
          std::cout << "*** Start of ChangeA: "<< ChangeA << " ChangeB: " << ChangeB << "\n";
          std::cout << "  A before: " << A << " <" << FormA << ">\n";
          std::cout << "  B: "<<B<<" <"<<FormB<<">\n";
          std::cout << "  C: "<<C<<" <"<<FormC<<">\n";
          std::cout << "  D: "<<D<<" <"<<FormD<<">\n";
          std::cout << "  Row: "<<Row<<" Column: "<<Column<<"\n";
#endif
          if ((A==Null_)&&(D==Null_)) {
           Formula.List.push_back(FormulaElement(0, FormA, FormB, FormC, FormD));
           A = B*C;
           count0++;
#ifdef DEBUG_
           std::cout << "  Formula 0: A=B*C\n";
#endif
          } else
          if ((A!=Null_)&&(D==Null_)) {
           Formula.List.push_back(FormulaElement(1, FormA, FormB, FormC, FormD));
           A += B*C;
           count1++;
#ifdef DEBUG_
           std::cout << "  Formula 1: A=A+B*C\n";
#endif
          } else
          if ((A==Null_)&&(D!=Null_)) {
           Formula.List.push_back(FormulaElement(2, FormA, FormB, FormC, FormD));
           A = B*C/(One_-D);
           count2++;
#ifdef DEBUG_
           std::cout << "  Formula 2: A=B*C/(1-D)\n";
#endif
          } else
          if ((A!=Null_)&&(D!=Null_)) {
           Formula.List.push_back(FormulaElement(3, FormA, FormB, FormC, FormD));
           A += B*C/(One_-D);
           count3++;
#ifdef DEBUG_
           std::cout << "  Formula 3: A=A+B*C/(1-D)\n";
#endif
          }
          *(SMatrix_+FormA)=A;
#ifdef DEBUG_
          std::cout << "  A after: " << A << "<" << FormA << ">\n";
#endif
         }
        }
        Column++;
       }
      }
     }
     Row++;
    }
    *(BVector+ChangeB)=true;
    *(AVector+ChangeA)=true;
  }

  FormulaExists_=true;

#ifdef DEBUG_
  std::cout << S11_ << " " << S12_ << " " << S21_ << " " << S22_ << std::endl;
  std::cout << count0 << " " << count1 << " " << count2 << " " << count3 << " (" <<
               count0+count1+count2+count3 << ")" << std::endl;
  std::cout << "S11: " << s11() << "\n";
  std::cout << "S12: " << s12() << "\n";
  std::cout << "S21: " << s21() << "\n";
  std::cout << "S22: " << s22() << "\n";
  std::cout << print();
#endif

  return Formula.List.count();
}
Ejemplo n.º 27
0
void AddAppletDialog::populateApplets()
{
    m_appletBox = new QWidget(m_mainWidget->appletScrollView->viewport());
    m_appletBox->setPaletteBackgroundColor(KGlobalSettings::baseColor());
    m_mainWidget->appletScrollView->addChild(m_appletBox, 0, 0);
    m_appletBox->show();
    QVBoxLayout* layout = new QVBoxLayout(m_appletBox);
    layout->setMargin(0);
    
    m_mainWidget->appletScrollView->installEventFilter(this);

    /* Three steps
     * - First we load the applets
     * - We load the special buttons
     * - Then we begin to populate the scrollview with the AppletWidget(s)
     */
    AppletInfo::List appletInfoList;

    // Loading applets
    appletInfoList = PluginManager::applets(false, &appletInfoList);

    // Loading built in buttons
    appletInfoList = PluginManager::builtinButtons(false, &appletInfoList);

    // Loading special buttons
    appletInfoList = PluginManager::specialButtons(false, &appletInfoList);

    qHeapSort(appletInfoList);

    int i = 0;
    bool odd = true;
    QWidget* prevTabWidget = m_mainWidget->appletFilter;

    for (AppletInfo::List::iterator it = appletInfoList.begin();
         !m_closing && it != appletInfoList.end();
         ++i)
    {
        if ((*it).isHidden() || (*it).name().isEmpty() ||
            ((*it).isUniqueApplet() &&
             PluginManager::the()->hasInstance(*it)))
        {
            it = appletInfoList.erase(it);
            --i;
            continue;
        }

        AppletWidget *itemWidget = new AppletWidget(*it, odd, m_appletBox);

        if (m_mainWidget->appletSearch->text().isEmpty() ||
            appletMatchesSearch(itemWidget, m_mainWidget->appletSearch->text()))
        {
            itemWidget->show();
            odd = !odd;
        }
        else
        {
            itemWidget->hide();
        }

        layout->insertWidget(i, itemWidget);
        m_appletWidgetList.append(itemWidget);
        setTabOrder(prevTabWidget, itemWidget);
        prevTabWidget = itemWidget;

        connect(itemWidget, SIGNAL(clicked(AppletWidget*)),
                this, SLOT(selectApplet(AppletWidget*)));
        connect(itemWidget, SIGNAL(doubleClicked(AppletWidget*)),
                this, SLOT(addApplet(AppletWidget*)));

        if (m_closing)
        {
            return;
        }

        ++it;
    }
    
    resizeAppletView();
    
    m_mainWidget->closeButton->setEnabled(true);
}
Ejemplo n.º 28
0
void SummaryWidget::updateView()
{
  mLayouts.setAutoDelete( true );
  mLayouts.clear();
  mLayouts.setAutoDelete( false );

  mLabels.setAutoDelete( true );
  mLabels.clear();
  mLabels.setAutoDelete( false );

  if ( mStations.count() == 0 ) {
    kdDebug(5602) << "No weather stations defined..." << endl;
    return;
  }


  QValueList<WeatherData> dataList = mWeatherMap.values();
  qHeapSort( dataList );

  QValueList<WeatherData>::Iterator it;
  for ( it = dataList.begin(); it != dataList.end(); ++it ) {
    QString cover;
    for ( uint i = 0; i < (*it).cover().count(); ++i )
      cover += QString( "- %1\n" ).arg( (*it).cover()[ i ] );

    QImage img;
    img = (*it).icon();

    QGridLayout *layout = new QGridLayout( mLayout, 3, 3, 3 );
    mLayouts.append( layout );

    KURLLabel* urlLabel = new KURLLabel( this );
    urlLabel->installEventFilter( this );
    urlLabel->setURL( (*it).stationID() );
    urlLabel->setPixmap( img.smoothScale( 32, 32 ) );
    urlLabel->setMaximumSize( urlLabel->sizeHint() );
    urlLabel->setAlignment( AlignTop );
    layout->addMultiCellWidget( urlLabel, 0, 1, 0, 0 );
    mLabels.append( urlLabel );
    connect ( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
              this, SLOT( showReport( const QString& ) ) );

    QLabel* label = new QLabel( this );
    label->setText( QString( "%1 (%2)" ).arg( (*it).name() ).arg( (*it).temperature() ) );
    QFont font = label->font();
    font.setBold( true );
    label->setFont( font );
    label->setAlignment( AlignLeft );
    layout->addMultiCellWidget( label, 0, 0, 1, 2 );
    mLabels.append( label );

    QString labelText;
    labelText = QString( "<b>%1:</b> %2<br>"
                         "<b>%3:</b> %4<br>"
                         "<b>%5:</b> %6" )
                         .arg( i18n( "Last updated on" ) )
                         .arg( (*it).date() )
                         .arg( i18n( "Wind Speed" ) )
                         .arg( (*it).windSpeed() )
                         .arg( i18n( "Rel. Humidity" ) )
                         .arg( (*it).relativeHumidity() );

    QToolTip::add( label, labelText.replace( " ", "&nbsp;" ) );

    label = new QLabel( cover, this );
    label->setAlignment( AlignLeft );
    layout->addMultiCellWidget( label, 1, 1, 1, 2 );
    mLabels.append( label );
  }

  for ( QLabel *label = mLabels.first(); label; label = mLabels.next() )
    label->show();
}
void KMyMoneySecuritySelector::update(const QString& id)
{
    MyMoneySecurity curr = MyMoneyFile::instance()->baseCurrency();
    QString baseCurrency = curr.id();

    if(!id.isEmpty())
        curr = m_currency;

    this->clear();
    m_list.clear();
    if(m_displayType & TypeCurrencies)
        m_list += MyMoneyFile::instance()->currencyList();
    if(m_displayType & TypeSecurities)
        m_list += MyMoneyFile::instance()->securityList();

    // sort
    qHeapSort(m_list);

    QValueList<MyMoneySecurity>::ConstIterator it;

    // construct a transparent 16x16 pixmap
    QPixmap empty(16, 16);
    empty.setMask(QBitmap(16, 16, true));

    int itemId = 0;
    int m_selectedItemId = 0;
    for(it = m_list.begin(); it != m_list.end(); ++it) {
        QString display;
        switch(m_displayItem) {
        default:
        case FullName:
            if((*it).isCurrency()) {
                display = QString("%2 (%1)").arg((*it).id()).arg((*it).name());
            } else
                display = QString("%2 (%1)").arg((*it).tradingSymbol()).arg((*it).name());
            break;
            break;

        case Symbol:
            if((*it).isCurrency())
                display = (*it).id();
            else
                display = (*it).tradingSymbol();
            break;
        }
        if((*it).id() == baseCurrency) {
            insertItem(QPixmap( locate("icon","hicolor/16x16/apps/kmymoney2.png")),
                       display, itemId);
        } else {
            insertItem(empty, display, itemId);
        }

        if(curr.id() == (*it).id()) {
            m_selectedItemId = itemId;
            m_currency = (*it);
        }

        itemId++;
    }
    setCurrentItem(m_selectedItemId);
}