void CalculateAmplitudes::setProgress(int row, int progress) {
    QProgressBar *progressBar = static_cast<QProgressBar*>(_ui.table->cellWidget(row, 3));
    _ui.table->setItem(row, 3, NULL);
    if ( !progressBar ) {
        progressBar = new QProgressBar(_ui.table);
        progressBar->setRange(0, 100);
        progressBar->setAlignment(Qt::AlignHCenter);
        QPalette pal = progressBar->palette();
        pal.setColor(QPalette::Highlight, Qt::darkGreen);
        progressBar->setPalette(pal);

        _ui.table->setCellWidget(row, 3, progressBar);
    }

    progressBar->setValue(progress);
    filterView(row, 1);
}
void MonitorDlg::update() {
  if (!m_tree) {
    m_tree = new QTreeWidget(this);
    m_tree->setColumnCount(3);
    m_tree->setSelectionMode(QAbstractItemView::NoSelection);
    // Make the algorithm name column wider
    m_tree->setColumnWidth(0, 220);
    QStringList hList;
    hList << "Algorithm"
          << "Progress"
          << "";
    m_tree->setHeaderLabels(hList);
    QHeaderView *hHeader = (QHeaderView *)m_tree->header();
    hHeader->setResizeMode(1, QHeaderView::Stretch);
    hHeader->setResizeMode(2, QHeaderView::Fixed);
    hHeader->setStretchLastSection(false);
  } else
    m_tree->clear();

  if (!isVisible())
    return;

  m_algMonitor->lock();
  QVector<Mantid::API::AlgorithmID>::const_iterator iend =
      m_algMonitor->algorithms().end();
  for (QVector<Mantid::API::AlgorithmID>::const_iterator itr =
           m_algMonitor->algorithms().begin();
       itr != iend; ++itr) {
    IAlgorithm_sptr alg =
        Mantid::API::AlgorithmManager::Instance().getAlgorithm(*itr);
    // m_algorithms << alg;
    QStringList iList;
    iList << QString::fromStdString(alg->name());
    QTreeWidgetItem *algItem = new QTreeWidgetItem(iList);
    m_tree->addTopLevelItem(algItem);
    QProgressBar *algProgress = new QProgressBar;
    algProgress->setAlignment(Qt::AlignHCenter);
    AlgButton *cancelButton = new AlgButton("Cancel", alg);
    m_tree->setItemWidget(algItem, 1, algProgress);
    m_tree->setItemWidget(algItem, 2, cancelButton);
    const std::vector<Mantid::Kernel::Property *> &prop_list =
        alg->getProperties();
    for (std::vector<Mantid::Kernel::Property *>::const_iterator prop =
             prop_list.begin();
         prop != prop_list.end(); ++prop) {
      QStringList lstr;
      Mantid::Kernel::MaskedProperty<std::string> *maskedProp =
          dynamic_cast<Mantid::Kernel::MaskedProperty<std::string> *>(*prop);
      if (maskedProp) {
        lstr << QString::fromStdString(maskedProp->name()) + ": "
             << QString::fromStdString(maskedProp->getMaskedValue());
      } else {
        lstr << QString::fromStdString((**prop).name()) + ": "
             << QString::fromStdString((**prop).value());
      }
      if ((**prop).isDefault())
        lstr << " Default";
      algItem->addChild(new QTreeWidgetItem(lstr));
    }

    connect(
        cancelButton, SIGNAL(clicked(Mantid::API::AlgorithmID, QPushButton *)),
        m_algMonitor, SLOT(cancel(Mantid::API::AlgorithmID, QPushButton *)));
  }
  m_algMonitor->unlock();
}
Example #3
0
void TrayMenu::addTorrent(RTorrent * torrent)
{
	no_torrent->setVisible(false);
	InfoAction * action = 0;
	QWidgetAction * waction = 0;
	QMenu * tmenu = new QMenu(menu);
	tmenu->setTitle(tr("Loading..."));

	//Add caption
	QLabel * lbl =  new QLabel(tr("<b>Torrent's info</b>"));
	lbl->setAlignment(Qt::AlignHCenter);
	waction = new QWidgetAction(tmenu);
	waction->setDefaultWidget(lbl);
	tmenu->addAction(waction);
	connect(torrent,SIGNAL(changeName(QString)),
		this,SLOT(changeName(QString)));

	//Add rate status
	action = new InfoAction(tmenu);
	action->setText(tr("%1, %2"));
	action->setText1(tr("UP: %1 kb/s"));
	action->setText2(tr("DOWN: %1 kb/s"));

	action->setParam1(tr("N/A"));
	action->setParam2(tr("N/A"));

	action->setIcon(QIcon(":/img/updown.png"));

	connect(torrent,SIGNAL(changeDownRate(double)),
		action,SLOT(setParam2(double)));

	connect(torrent,SIGNAL(changeUpRate(double)),
		action,SLOT(setParam1(double)));
	
	tmenu->addAction(action);

	//Add rateio status
	action = new InfoAction(tmenu);
	action->setText(tr("%1"));
	action->setText1(tr("Rateio: %1"));
	action->setParam1(tr("N/A"));

	connect(torrent,SIGNAL(changeRatio(double)),
		action,SLOT(setParam1(double)));
	tmenu->addAction(action);

	//Add progress
	QProgressBar * bar = new QProgressBar(tmenu);
	bar->setAlignment(Qt::AlignHCenter);
	waction = new QWidgetAction(tmenu);
	waction->setDefaultWidget(bar);
	tmenu->addAction(waction);

	connect(torrent,SIGNAL(changeCompletedChunks(int)),
		bar,SLOT(setValue(int)));

	connect(torrent,SIGNAL(changeSizeChunks(int)),
		bar,SLOT(setMaximum(int)));
	connect(torrent,SIGNAL(changeCompletedChunks(int)),
		this,SLOT(changeCompletedChunks(int)));

	//Add priority
	QComboBox * combo =  new QComboBox(tmenu);
	combo->addItem(QIcon(),tr("Idle"));
	combo->addItem(QIcon(),tr("Low"));
	combo->addItem(QIcon(),tr("Normal"));
	combo->addItem(QIcon(),tr("High"));
	combo->setEditable(false);

	waction = new QWidgetAction(tmenu);
	waction->setDefaultWidget(combo);
	tmenu->addAction(waction);

	connect(torrent,SIGNAL(changePriority(int)),
		combo,SLOT(setCurrentIndex (int)));
	connect(combo,SIGNAL(activated(int)),
		torrent,SLOT(setPriority(int)));
	
	//Other
	connect(torrent,SIGNAL(changeChunkSize(long)),
		this,SLOT(changeChunkSize(long)));
	connect(torrent,SIGNAL(changeState(int)),
		this,SLOT(changeState(int)));

	tmenu->addSeparator();
	QAction * command = 0;

	//control action
	command = tmenu->addAction(QIcon(":/img/close.png"),tr("Close"));
	connect(command,SIGNAL(triggered (bool)),
		torrent,SLOT(close(bool)));
	command = tmenu->addAction(QIcon(":/img/open.png"),tr("Start"));
	connect(command,SIGNAL(triggered (bool)),
		torrent,SLOT(start(bool)));
	command = tmenu->addAction(QIcon(":/img/stop.png"),tr("Stop"));
	connect(command,SIGNAL(triggered (bool)),
		torrent,SLOT(stop(bool)));
	command = tmenu->addAction(QIcon(":/img/rehash0.png"),tr("Rehash"));
	connect(command,SIGNAL(triggered (bool)),
		torrent,SLOT(check_hash(bool)));
	command = tmenu->addAction(QIcon(":/img/erase.png"),tr("Erase"));
	connect(command,SIGNAL(triggered (bool)),
		torrent,SLOT(erase(bool)));

	//connect AutoUpdate when menu visible
	connect(tmenu,SIGNAL(aboutToShow()),
		torrent, SLOT(fullUpdate()));
	connect(tmenu,SIGNAL(aboutToShow()),
		torrent,SLOT(enableAutoUpdate()));
	connect(tmenu,SIGNAL(aboutToHide()),
		torrent,SLOT(disableAutoUpdate()));

	torrents[torrent->getId()] = tmenu;
	menu->insertMenu(sep,tmenu);
}