Skip to content
Snippets Groups Projects
Select Git revision
  • d3fee7ecf41f26a06002aa141b0d3b91d252bb52
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

binary_data_sink.hh

Blame
  • widget_pool.cc 2.58 KiB
    //------------------------------------------------------------------------------
    // This file is part of the OpenStructure project <www.openstructure.org>
    //
    // Copyright (C) 2008-2010 by the OpenStructure authors
    //
    // This library is free software; you can redistribute it and/or modify it under
    // the terms of the GNU Lesser General Public License as published by the Free
    // Software Foundation; either version 3.0 of the License, or (at your option)
    // any later version.
    // This library is distributed in the hope that it will be useful, but WITHOUT
    // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    // FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    // details.
    //
    // You should have received a copy of the GNU Lesser General Public License
    // along with this library; if not, write to the Free Software Foundation, Inc.,
    // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    //------------------------------------------------------------------------------
    
    #include "widget_pool.hh"
    #include "widget_registry.hh"
    
    namespace ost { namespace gui {
    
      WidgetPool::WidgetPool(QObject* parent):
        QObject(parent)
      { }
    
      void WidgetPool::Add(const QString& name, int limit)
      {
        QString n=name;
        n.replace(".", "::");
        if (pool_.contains(n)) {
          return;
        }
        pool_[n]=PooledWidget(n, limit);
      }
    
      bool WidgetPool::IsAvailable(const QString& name)
      {
        QString n=name;
        n.replace(".", "::");
        if (pool_.contains(n)) {
          int av=pool_[n].available;
          return av==-1 || av>0;
        }
        return false;
      }
    
      Widget* WidgetPool::Create(const QString& name)
      {
        QString n=name;
        n.replace(".", "::");
        if (this->IsAvailable(n)) {
          return WidgetRegistry::Instance()->Create(n, NULL);
        }
        return NULL;
      }
    
      bool WidgetPool::Take(const QString& name)
      {
        QString n=name;
        n.replace(".", "::");
        if (this->IsAvailable(n)) {
          int av=pool_[n].available;
          pool_[n].available=av==-1 ? av : av-1;
          return true;
        }
        return false;
      }
    
      bool WidgetPool::Give(const QString& name)
      {
        QString n=name;
        n.replace(".", "::");
        if (pool_.contains(n)) {
          int av=pool_[n].available;
          pool_[n].available=av==-1 ? av : av+1;
          return true;
        }
        return false;
      }
    
      QList<QString> WidgetPool::GetAvailableWidgets()
      {
        QList<QString> av;
        for (QMap<QString, PooledWidget>::iterator i=pool_.begin(),
             e=pool_.end(); i!=e; ++i) {
    
          if (i.value().available==-1 || i.value().available>0) {
            av.push_back(i.key());
          }
        }
        return av;
      }
    
    }}