Logo Search packages:      
Sourcecode: packagesearch version File versions

void PackageSearchImpl::updateShortInformationPluginGui (  )  [protected]

Updates short information interface.

Shows the short information for all available short information plugins in the correct order, removing outdated ones.

Definition at line 439 of file packagesearchimpl.cpp.

References _hiddenShortInformation, _shortInformationColumn, _shortInformationPlugins, _shownShortInformation, NPlugin::ShortInformationPlugin::preferredColumnWidth(), NPlugin::ShortInformationPlugin::shortInformationCaption(), and NPlugin::ShortInformationPlugin::shortInformationPriority().

Referenced by addPlugin(), onPackageViewContextMenu(), and removePlugin().

{
      // remove all except the first column
      while ( _pPackageView->columns() > 0)
            _pPackageView->removeColumn(0);
/*    NExtStd::for_each(_shortInformationPlugins.begin(), _shortInformationPlugins.end(),
            &PackageSearchImpl::addShortInformationPluginToGui, this);*/
      const int CHAR_WIDTH = 7;
      const int MARGIN = 10;
      // sorted list of ShortInformationPlugins
      ShortInformationPluginContainer plugins = _shortInformationPlugins;
      // holds the plugins shown in order of priority
      ShortInformationPluginContainer shownPlugins;
      // add the shown plugins to be displayed and removed them from "plugins"
      for (QStringList::const_iterator it = _shownShortInformation.begin(); 
                  it != _shownShortInformation.end(); ++it)
      {
            ShortInformationPluginContainer::iterator jt = find_if(plugins.begin(), plugins.end(), ShortInformationCaptionEquals(*it));
            if (jt != plugins.end())
            {
                  NPlugin::ShortInformationPlugin* pPlugin = *jt;
                  int columnWidth = (pPlugin->preferredColumnWidth() == -1) ? -1 : (pPlugin->preferredColumnWidth() * CHAR_WIDTH + MARGIN);
                  int column = _pPackageView->addColumn(pPlugin->shortInformationCaption(), columnWidth);
                  _shortInformationColumn[pPlugin] = column;
                  _pPackageView->setColumnWidthMode(column, QListView::Manual);
                  plugins.erase(jt);
                  shownPlugins.push_back(*jt);
                  qDebug("Adding known plugin "+pPlugin->shortInformationCaption()+" as %d", _shortInformationColumn[pPlugin]);
            }
      }
      // remove the hidden plugins from "plugins"
      for (QStringList::const_iterator it = _hiddenShortInformation.begin(); 
                  it != _hiddenShortInformation.end(); ++it)
      {
            ShortInformationPluginContainer::iterator jt = find_if(plugins.begin(), plugins.end(), ShortInformationCaptionEquals(*it));
            if (jt != plugins.end())
                  plugins.erase(jt);
      }
      // handle new plugins (neither shown nor hidden) adding them before the first
      // plugin which has a priority greater than the one of the new one
      for ( ShortInformationPluginContainer::iterator it = plugins.begin();
            it != plugins.end(); ++it )
      {
            NPlugin::ShortInformationPlugin* pPlugin = *it;
            qDebug("Adding new plugin "+pPlugin->shortInformationCaption()+" as %d", _shortInformationColumn[pPlugin]);
            int columnWidth = (pPlugin->preferredColumnWidth() == -1) ? -1 
                        : (pPlugin->preferredColumnWidth() * CHAR_WIDTH + MARGIN);
            int column = _pPackageView->addColumn(pPlugin->shortInformationCaption(), columnWidth);
            _shortInformationColumn[pPlugin] = column;
            _shortInformationColumn[pPlugin] = column;
            _pPackageView->setColumnWidthMode(column, QListView::Manual);

            // not working because pointer spoil the show (the binder can't cope with this :-(
//          LesserPriority<NPlugin::ShortInformationPlugin> cmp;
//          ShortInformationPluginContainer::const_iterator jt = find_if(plugins.begin(), plugins.end(), bind1st<NPlugin::ShortInformationPlugin*>(cmp, pPlugin));
            ShortInformationPluginContainer::const_iterator jt;
            // find the first plugin with a higher priority value (i.e. a lower piority)
            for (jt = shownPlugins.begin(); jt != shownPlugins.end(); ++jt)
            {
                  if ( (*jt)->shortInformationPriority() > pPlugin->shortInformationPriority() )
                        break;
            }
            // if such plugin was found move the new plugin in front of the other
            if (jt != shownPlugins.end())
            {
                  int sectionOther = _shortInformationColumn[*jt];
                  int indexOther = _pPackageView->header()->mapToIndex(sectionOther);
                  int sectionThis = _shortInformationColumn[pPlugin];
                  _pPackageView->header()->moveSection(sectionThis, indexOther);
                  // insert the name of the plugin before the one found
                  QStringList::iterator kt = _shownShortInformation.find((*jt)->shortInformationCaption());
                  _shownShortInformation.insert(kt, pPlugin->shortInformationCaption());
            }
            else
            {
                  _shownShortInformation.push_back(pPlugin->shortInformationCaption());
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index