Ejemplo n.º 1
0
int test_iterator_15()
{
	// std::istreambuf_iterator: 输入流缓存迭代器
	std::istreambuf_iterator<char> eos;                    // end-of-range iterator
	std::istreambuf_iterator<char> iit(std::cin.rdbuf()); // stdin iterator
	std::string mystring;

	std::cout << "Please, enter your name: ";

	while (iit != eos && *iit != '\n') mystring += *iit++;

	std::cout << "Your name is " << mystring << ".\n";

	return 0;
}
Ejemplo n.º 2
0
void Factory::load(string const & typeName, string const & fileName){
	std::fstream in(fileName.c_str());
	if (in) {
		std::istream_iterator<string> iit(in);
		std::istream_iterator<string> eos;
		if(!find(typeName).get()){
			tDescr descr = new Description(typeName);
			while(iit != eos){
				descr->add(*iit);
				iit++;
			}
			_cash[typeName] = descr;
		}
	}
}
Ejemplo n.º 3
0
int main()
{
	double value1, value2;
	std::cout << "Please, insert two values: ";

	std::istream_iterator<double> eos;         // end-of-stream iterator
	std::istream_iterator<double> iit (std::cin);   // stdin iterator

	if (iit!=eos) value1=*iit;

	iit++;
	if (iit!=eos) value2=*iit;

	std::cout << value1 << "*" << value2 << "=" << (value1*value2) << std::endl;
	return 0;
}
Ejemplo n.º 4
0
int test_iterator_16()
{
	// std::istream_iterator: 从输入流读取连续元素的输入迭代器
	double value1, value2;
	std::cout << "Please, insert two values: ";

	std::istream_iterator<double> eos;              // end-of-stream iterator
	std::istream_iterator<double> iit(std::cin);   // stdin iterator

	if (iit != eos) value1 = *iit;

	++iit;
	if (iit != eos) value2 = *iit;

	std::cout << value1 << "*" << value2 << "=" << (value1*value2) << '\n';

	return 0;
}
Ejemplo n.º 5
0
RsHash binsvd_pred::predict(RsHash valid, bool verbose)
{
    if (verbose) printf("Binsvd predicting...\n");

    RsHash new_valid(valid);

    // iterate through users (valid)
    RsHashIter uit(valid);
    int users_n = valid.size(), n = 0;
    while (uit.hasNext()) {
        uit.next();
        n++;
        int u = uit.key();
        // iterate through user valid ratings
        QHashIterator<int, float> iit(uit.value());
        while (iit.hasNext()) {
            iit.next();
            int i = iit.key();

            // compute "rating" as dot product of factor vectors
            float r = 0;
            QVector<float> v;
            if (!item_factors.contains(i))
            {
                for(int j = 0; j < user_factors[u].count(); j++)
                {
                    v.append(1);
                }
                r = dot_product(user_factors[u], v, user_factors[u].count());
            }
            else
                r = dot_product(user_factors[u], item_factors[i], user_factors[u].count());
            new_valid[u][i] = r;
        }
        if (verbose) printf("%3.3f %% complited\r", float(n) / users_n * 100);
    }
    valid = new_valid;
    
    if (verbose) printf("ok\n");

    return valid;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) {
	if (argc != 2) {
		std::cerr << "Usage: " <<
			argv[0] << " file\n";
		exit(EXIT_FAILURE);
	}
	std::ifstream file(argv[1]);
	if (!file) {
		std::cerr << "can't open file" << argv[1] << std::endl;
		exit(EXIT_FAILURE);
	}

   

	std::istreambuf_iterator<char> iit(file.rdbuf()), eos;
	std::string cnt(iit, eos);
	file.close();
	std::cout << "file size: " << cnt.size() << std::endl;
	Generator g(cnt);
}
Ejemplo n.º 7
0
void RelationsWidget::populate(QString filepath)
{
    relationsTree->clear();

/*    relationsBoth << "_"
                  << "suj"
                  << "obj"
                  << "de_obj"
                  << "a_obj"
                  << "p_obj_loc"
                  << "p_obj_dloc"
                  << "p_obj"
                  << "ats"
                  << "ato"
                  << "mod_loc"
                  << "mod_cleft"
                  << "mod"
                  << "ponct"
                  << "dep_coord"
                  << "coord"
                  << "mod_rel"
                  << "arg"
                  << "det"
                  << "dep"
                  << "arg_comp"
                  << "arg_cons";
*/

//    relationsInit << "arg_caus";
/*    relationsFinal << "aux_tps"
                   << "aux_pass"
                   << "aux_caus"
                   << "aff_moyen"
                   << "aff_neutre"
                   << "aff_secaus"
                   << "aff"
                   << "dis"
                   << "p_obj_agt";
*/

/*    relationsFinal << "_"
                   << "a_obj"
                   << "aff"
                   << "aff_moyen"
                   << "aff_neutre"
                   << "aff_secaus"
                   << "arg"
                   << "arg_comp"
                   << "arg_cons"
                   << "ato"
                   << "ats"
                   << "aux_caus"
                   << "aux_pass"
                   << "aux_tps"
                   << "coord"
                   << "de_obj"
                   << "dep"
                   << "dep_coord"
                   << "det"
                   << "dis"
                   << "mod"
                   << "mod_cleft"
                   << "mod_loc"
                   << "mod_rel"
                   << "obj"
                   << "p_obj"
                   << "p_obj_agt"
                   << "p_obj_dloc"
                   << "p_obj_loc"
                   << "ponct"
                   << "suj";

    relationsInit << "_"
                  << "a_obj"
                  << "aff"
                  << "aff_moyen"
                  << "aff_neutre"
                  << "aff_secaus"
                  << "arg"
                  << "arg_caus"
                  << "arg_comp"
                  << "arg_cons"
                  << "ato"
                  << "ats"
                  << "aux_caus"
                  << "aux_pass"
                  << "aux_tps"
                  << "coord"
                  << "de_obj"
                  << "dep"
                  << "dep_coord"
                  << "det"
                  << "dis"
                  << "mod"
                  << "mod_cleft"
                  << "mod_loc"
                  << "mod_rel"
                  << "obj"
                  << "p_obj"
                  << "p_obj_agt"
                  << "p_obj_dloc"
                  << "p_obj_loc"
                  << "ponct"
                  << "suj";   */

    reader->read(filepath);


    QMap<QString, QString> fins = reader->finals();

    if(!reader->initials().isEmpty()){
        QMap<QString, QString> inits = reader->initials();

        QTreeWidgetItem *parentInit = new QTreeWidgetItem(QStringList() << "Canonique");
        QMapIterator<QString, QString> iit(inits);
        while(iit.hasNext()){
            iit.next();
            QTreeWidgetItem *i = new QTreeWidgetItem(QStringList() << iit.key());
            i->setToolTip(0, iit.value());
            parentInit->addChild(i);
        }

        QTreeWidgetItem *parentFinal = new QTreeWidgetItem(QStringList() << "Final");
        QMapIterator<QString, QString> fit(fins);
        while(fit.hasNext()){
            fit.next();
            QTreeWidgetItem *i = new QTreeWidgetItem(QStringList() << fit.key());
            i->setToolTip(0, fit.value());
            parentFinal->addChild(i);
        }
        relationsTree->insertTopLevelItems(0, QList<QTreeWidgetItem*>() << parentInit
                                           << parentFinal);
        parentInit->setExpanded(true);
        parentFinal->setExpanded(true);
    }else{
        QList<QTreeWidgetItem*> items;
        QMapIterator<QString, QString> fit(fins);
        while(fit.hasNext()){
            fit.next();
            QTreeWidgetItem *i = new QTreeWidgetItem(QStringList() << fit.key());
            i->setToolTip(0, fit.value());
            items << i;
        }
        relationsTree->insertTopLevelItems(0, items);
    }
}
Ejemplo n.º 8
0
void InputOutputPatchEditor::fillMappingTree()
{
    /* Disable check state change tracking when the tree is filled */
    disconnect(m_mapTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
               this, SLOT(slotMapItemChanged(QTreeWidgetItem*, int)));

    m_mapTree->clear();

    /* Go through available input plugins and create tree nodes. */
    QStringListIterator inputIt(m_inputMap->pluginNames());
    while (inputIt.hasNext() == true)
    {
        quint32 i = 0;
        QString pluginName = inputIt.next();
        QStringListIterator iit(m_inputMap->pluginInputs(pluginName));
        while (iit.hasNext() == true)
        {
            QTreeWidgetItem* pitem = new QTreeWidgetItem(m_mapTree);
            pitem->setText(KMapColumnPluginName, pluginName);
            pitem->setText(KMapColumnDeviceName, iit.next());
            pitem->setFlags(pitem->flags() | Qt::ItemIsUserCheckable);
            if (m_currentInputPluginName == pluginName && m_currentInput == i)
                pitem->setCheckState(KMapColumnHasInput, Qt::Checked);
            else
                pitem->setCheckState(KMapColumnHasInput, Qt::Unchecked);
            pitem->setTextAlignment(KMapColumnHasInput, Qt::AlignHCenter);
            pitem->setText(KMapColumnInputLine, QString("%1").arg(i));
            pitem->setText(KMapColumnOutputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
            i++;
        }

        if (i == 0)
        {
            QTreeWidgetItem* pitem = new QTreeWidgetItem(m_mapTree);
            pitem->setText(KMapColumnPluginName, pluginName);
            pitem->setText(KMapColumnDeviceName, KInputNone);
            pitem->setText(KMapColumnInputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
            pitem->setText(KMapColumnOutputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
        }
    }
    /* Go through available output plugins and create/update tree nodes. */
    QStringListIterator outputIt(m_outputMap->pluginNames());
    while (outputIt.hasNext() == true)
    {
        QString pluginName = outputIt.next();
        quint32 i = 0;

        QTreeWidgetItem *item = itemLookup(pluginName, "");
        /* 1st case: Add new plugin */
        if (item == NULL)
        {
            QStringListIterator iit(m_outputMap->pluginOutputs(pluginName));
            while (iit.hasNext() == true)
            {
                /* Output capable device */
                QString devName = iit.next();
                QTreeWidgetItem* pitem = new QTreeWidgetItem(m_mapTree);
                pitem->setText(KMapColumnPluginName, pluginName);
                pitem->setText(KMapColumnDeviceName, devName);
                pitem->setFlags(pitem->flags() | Qt::ItemIsUserCheckable);
                if (m_currentOutputPluginName == pluginName && m_currentOutput == i)
                    pitem->setCheckState(KMapColumnHasOutput, Qt::Checked);
                else
                    pitem->setCheckState(KMapColumnHasOutput, Qt::Unchecked);
                pitem->setText(KMapColumnOutputLine, QString("%1").arg(i));
                pitem->setText(KMapColumnInputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
                /* If a device has an output, it means it can send feedbacks */
                if (pluginName == "MIDI")
                {
                    if (m_currentFeedbackPluginName == pluginName && m_currentFeedback == i)
                        pitem->setCheckState(KMapColumnHasFeedback, Qt::Checked);
                    else
                        pitem->setCheckState(KMapColumnHasFeedback, Qt::Unchecked);
                }
                i++;
            }
            if (i == 0)
            {
                /* Device not available: No input and no output */
                QTreeWidgetItem* pitem = new QTreeWidgetItem(m_mapTree);
                pitem->setText(KMapColumnPluginName, pluginName);
                pitem->setText(KMapColumnDeviceName, KInputNone);
                pitem->setText(KMapColumnOutputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
                pitem->setText(KMapColumnInputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
            }
        }
        else
        {
            QStringListIterator iit(m_outputMap->pluginOutputs(pluginName));
            while (iit.hasNext() == true)
            {
                QString devName = iit.next();
                QTreeWidgetItem *item = itemLookup(pluginName, devName);
                /* 2nd case: add new output-only device to an existing plugin */
                if (item == NULL)
                {
                    item = new QTreeWidgetItem(m_mapTree);
                    item->setText(KMapColumnPluginName, pluginName);
                    item->setText(KMapColumnDeviceName, devName);
                    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
                    if (m_currentOutputPluginName == pluginName && m_currentOutput == i)
                        item->setCheckState(KMapColumnHasOutput, Qt::Checked);
                    else
                        item->setCheckState(KMapColumnHasOutput, Qt::Unchecked);

                    item->setText(KMapColumnOutputLine, QString("%1").arg(i));
                    item->setText(KMapColumnInputLine, QString("%1").arg(QLCIOPlugin::invalidLine()));
                }
                else
                {
                    /* 3rd case: add an output line to an existing device with an input line */
                    item->setText(KMapColumnDeviceName, devName);
                    if (m_currentOutputPluginName == pluginName && m_currentOutput == i)
                        item->setCheckState(KMapColumnHasOutput, Qt::Checked);
                    else
                        item->setCheckState(KMapColumnHasOutput, Qt::Unchecked);
                    item->setText(KMapColumnOutputLine, QString("%1").arg(i));
                }
                /* If a device has both input and output, it means it can send feedbacks */
                if (pluginName == "MIDI")
                {
                    if (m_currentFeedbackPluginName == pluginName && m_currentFeedback == i)
                        item->setCheckState(KMapColumnHasFeedback, Qt::Checked);
                    else
                        item->setCheckState(KMapColumnHasFeedback, Qt::Unchecked);
                }
                i++;
            }
        }
    }

    /* Enable check state change tracking after the tree has been filled */
    connect(m_mapTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
            this, SLOT(slotMapItemChanged(QTreeWidgetItem*, int)));
}
Ejemplo n.º 9
0
void mitk::CLUtil::itkInterpolateCheckerboardPrediction(TImageType * checkerboard_prediction, Image::Pointer &checkerboard_mask, mitk::Image::Pointer & outimage)
{
  typename TImageType::Pointer itk_checkerboard_mask;
  mitk::CastToItkImage(checkerboard_mask,itk_checkerboard_mask);

  typename TImageType::Pointer itk_outimage = TImageType::New();
  itk_outimage->SetRegions(checkerboard_prediction->GetLargestPossibleRegion());
  itk_outimage->SetDirection(checkerboard_prediction->GetDirection());
  itk_outimage->SetOrigin(checkerboard_prediction->GetOrigin());
  itk_outimage->SetSpacing(checkerboard_prediction->GetSpacing());
  itk_outimage->Allocate();
  itk_outimage->FillBuffer(0);

  //typedef typename itk::ShapedNeighborhoodIterator<TImageType>::SizeType SizeType;
  typedef itk::Size<3> SizeType;
  SizeType size;
  size.Fill(1);
  itk::ShapedNeighborhoodIterator<TImageType> iit(size,checkerboard_prediction,checkerboard_prediction->GetLargestPossibleRegion());
  itk::ShapedNeighborhoodIterator<TImageType> mit(size,itk_checkerboard_mask,itk_checkerboard_mask->GetLargestPossibleRegion());
  itk::ImageRegionIterator<TImageType> oit(itk_outimage,itk_outimage->GetLargestPossibleRegion());

  typedef typename itk::ShapedNeighborhoodIterator<TImageType>::OffsetType OffsetType;
  OffsetType offset;
  offset.Fill(0);
  offset[0] = 1;       // {1,0,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[0] = -1;      // {-1,0,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[0] = 0; offset[1] = 1; //{0,1,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);
  offset[1] = -1;      //{0,-1,0}
  iit.ActivateOffset(offset);
  mit.ActivateOffset(offset);

  //    iit.ActivateOffset({{0,0,1}});
  //    iit.ActivateOffset({{0,0,-1}});
  //    mit.ActivateOffset({{0,0,1}});
  //    mit.ActivateOffset({{0,0,-1}});

  while(!iit.IsAtEnd())
  {
    if(mit.GetCenterPixel() == 0)
    {
      typename TImageType::PixelType mean = 0;
      for (auto i = iit.Begin(); ! i.IsAtEnd(); i++)
      { mean += i.Get(); }


      //std::sort(list.begin(),list.end(),[](const typename TImageType::PixelType x,const typename TImageType::PixelType y){return x<=y;});

      oit.Set((mean+0.5)/6.0);
    }
    else
    {
      oit.Set(iit.GetCenterPixel());
    }
    ++iit;
    ++mit;
    ++oit;
  }

  mitk::CastToMitkImage(itk_outimage,outimage);
}
Ejemplo n.º 10
0
int main() {

	//File PARITY
	std::fstream parity_file("..\\..\\data\\PARITY.txt");
	if (!parity_file)
		return 1;

	std::istream_iterator<long> eos;
	std::istream_iterator<long> iit(parity_file);

	const long rows = *iit++;
	const long cols = *iit++;

	std::vector<std::vector<long>> check(rows), bit(cols);

	std::cout << "Reading PARITY...\n";

	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();

	//Initial bit_connections and check_connections
	while (iit != eos) {
		long left = *iit;
		++iit;
		check[left - 1].push_back(*iit);
		bit[*iit - 1].push_back(left);
		++iit;
	}
	std::chrono::system_clock::time_point end = std::chrono::system_clock::now();

	int sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	int msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done reading in " << sec << " s " << msec << " ms\n";

	//File demodSignal
	std::fstream signal_file("..\\..\\data\\demodSignal.txt");
	if (!signal_file) { std::cout << "Error with opening demodSignal.txt\n" << std::endl; return 1; }

	std::istream_iterator<float> eos_d;
	std::istream_iterator<float> iit_d(signal_file);

	std::vector<float> demodSignal;

	std::cout << "Reading demodSignal...\n";

	start = std::chrono::system_clock::now();

	//Reading demodSignal file
	while (iit_d != eos_d) {
		demodSignal.push_back(*iit_d);
		++iit_d;
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done reading in " << sec << " s " << msec << " ms\n";

	//Initialization posylka_from_bit_to_check
	std::vector<std::vector<float>> posylka_from_bit_to_check(cols);
	std::vector<std::vector<long>>::iterator iter_p = bit.begin();
	int num_d = 0;//Íîìåð èíäåêñà ñèãíàëà

	std::cout << "Preparing posylka_from_bit_to_check...\n";

	start = std::chrono::system_clock::now();

	while (iter_p != bit.end()) {
		for (int i = 0; i < bit[num_d].size(); i++) {

			posylka_from_bit_to_check[num_d].push_back(demodSignal[num_d]);
		}
		num_d++;
		++iter_p;
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done preparing in " << sec << " s " << msec << " ms\n";

	//Initialization posylka_from_check_to_bit
	std::vector<std::vector<float>> posylka_from_check_to_bit(rows);

	const int MaxIteration = 50;

	//Íà÷àëàñü îòïðàâêà
	start = std::chrono::system_clock::now();

	for (int n_iter = 0; n_iter < MaxIteration; n_iter++) {
		std::cout << "\n" << n_iter + 1 << " iterations\n";
		std::vector<long>::iterator it_find;
		std::vector<long> d; // Çàïèñûâàåòñÿ èñïðàâëÿåìûé ñèãíàë
		std::vector<float> LQ;

		//std::cout << "Otpravka: \n";

		for (int nn = 0; nn < rows; nn++) {
			std::vector<long> input_indeces = check[nn];
			std::vector<long>::iterator it_ii = input_indeces.begin();
			std::vector<float> posylki;

			//Chto imenno prihodilo:
			while (it_ii != input_indeces.end()) {

				it_find = std::find(bit[*it_ii - 1].begin(), bit[*it_ii - 1].end(), nn + 1);
				int num_it_find = it_find - bit[*it_ii - 1].begin();
				float tmp = posylka_from_bit_to_check[*it_ii - 1][num_it_find];
				++it_ii;
				posylki.push_back(tmp);
			}

			posylka_from_check_to_bit[nn].clear(); // Ñòèðàåì äëÿ çàïîëíåíèÿ îáíîâëåííûìè çíà÷åíèÿìè

			//Formiruem otvet
			for (int kk = 0; kk < input_indeces.size(); kk++) {
				std::vector<float> posyl_minus_1(posylki);

				posyl_minus_1.erase(posyl_minus_1.begin() + kk);
				float gg = g_func(posyl_minus_1);
				posylka_from_check_to_bit[nn].push_back(gg);
			}
		}

		//std::cout << "Otvet:\n";

		//bit node update
		for (int nn = 0; nn < cols; nn++) {
			std::vector<long> input_indeces = bit[nn];
			std::vector<long>::iterator it_ii = input_indeces.begin();
			std::vector<float> posylki;

			//Chto imenno prihodilo:
			while (it_ii != input_indeces.end()) {
				
				it_find = std::find(check[*it_ii - 1].begin(), check[*it_ii - 1].end(), nn + 1);
				int num_it_find = it_find - check[*it_ii - 1].begin();
				float tmp = posylka_from_check_to_bit[*it_ii - 1][num_it_find];
				++it_ii;
				posylki.push_back(tmp);
			}

			posylka_from_bit_to_check[nn].clear();

			//Formiruem otvet
			for (int kk = 0; kk < input_indeces.size(); kk++) {
				std::vector<float> posyl_minus_1(posylki);
				
				posyl_minus_1.erase(posyl_minus_1.begin() + kk);
				float gg = demodSignal[nn] + sum(posyl_minus_1);
				posylka_from_bit_to_check[nn].push_back(gg);
			}

			LQ.push_back(demodSignal[nn] + sum(posylki));
			d.push_back((1 - Sign(LQ[nn])) / 2);
		}

		//Ñîçäàåì è çàïîëíÿåì ñèíäîðì
		std::vector<long> syndrome;
		for (int i = 0; i < rows; i++) {
			std::vector<long> indeces = check[i];
			std::vector<long>::iterator it_ind = indeces.begin();
			std::vector<long> tmp;

			while (it_ind != indeces.end()) {
				tmp.push_back(d[*it_ind - 1]);
				it_ind++;
			}

			syndrome.push_back(fmod(sum(tmp), 2));
		}

		std::cout << "\nErrors: " << sum(syndrome) << std::endl;
		if (sum(syndrome) == 0) { break; }
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "\nDone preparing in " << sec << " s " << msec << " ms\n";

	std::cout << "SYNDROME == 0" << std::endl;

	system("pause");

	return 0;
}
Ejemplo n.º 11
0
void InputPatchEditor::fillMappingTree()
{
	QTreeWidgetItem* iitem = NULL;
	QTreeWidgetItem* pitem = NULL;
	QString pluginName;
	int i;

	/* Disable check state change tracking when the tree is filled */
	disconnect(m_mapTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
		   this, SLOT(slotMapItemChanged(QTreeWidgetItem*)));

	m_mapTree->clear();

	/* Add an empty item so that user can choose not to assign any plugin
	   to an input universe */
	pitem = new QTreeWidgetItem(m_mapTree);
	pitem->setText(KMapColumnName, KInputNone);
	pitem->setText(KMapColumnInput, QString("%1").arg(KInputInvalid));
	pitem->setFlags(pitem->flags() | Qt::ItemIsUserCheckable);

	/* Set "Nothing" selected if there is no valid input selected */
	if (m_currentInput == KInputInvalid)
		pitem->setCheckState(KMapColumnName, Qt::Checked);
	else
		pitem->setCheckState(KMapColumnName, Qt::Unchecked);

	/* Go thru available plugins and put them as the tree's root nodes. */
	QStringListIterator pit(_app->inputMap()->pluginNames());
	while (pit.hasNext() == true)
	{
		i = 0;

		pluginName = pit.next();
		pitem = new QTreeWidgetItem(m_mapTree);
		pitem->setText(KMapColumnName, pluginName);
		pitem->setText(KMapColumnInput, QString("%1")
							.arg(KInputInvalid));

		/* Go thru available inputs provided by each plugin and put
		   them as their parent plugin's leaf nodes. */
		QStringListIterator iit(
			_app->inputMap()->pluginInputs(pluginName));
		while (iit.hasNext() == true)
		{
			iitem = new QTreeWidgetItem(pitem);
			iitem->setText(KMapColumnName, iit.next());
			iitem->setText(KMapColumnInput, QString("%1").arg(i));
			iitem->setFlags(iitem->flags() |
					Qt::ItemIsUserCheckable);

			/* Select the currently mapped plugin input and expand
			   its parent node. */
			if (m_currentPluginName == pluginName &&
			    m_currentInput == i)
			{
				iitem->setCheckState(KMapColumnName,
						     Qt::Checked);
				pitem->setExpanded(true);
			}
			else
			{
				int uni;

				iitem->setCheckState(KMapColumnName,
						     Qt::Unchecked);
				uni = _app->inputMap()->mapping(pluginName, i);
				if (uni != -1)
				{
					/* If a mapping exists for this plugin
					   and output, make it impossible to
					   map it to another universe. */
					iitem->setFlags(iitem->flags()
							& (!Qt::ItemIsEnabled));
					iitem->setText(KMapColumnName,
						iitem->text(KMapColumnName) +
						QString(" (Mapped to universe %1)")
							.arg(uni + 1));
				}


			}

			i++;
		}

		/* If no inputs were appended to the plugin node, put a
		   "Nothing" node there. */
		if (i == 0)
		{
			iitem = new QTreeWidgetItem(pitem);
			iitem->setText(KMapColumnName, KInputNone);
			iitem->setText(KMapColumnInput,
				       QString("%1").arg(KInputInvalid));
			iitem->setFlags(iitem->flags() & ~Qt::ItemIsEnabled);
			iitem->setFlags(iitem->flags() & ~Qt::ItemIsSelectable);
			iitem->setCheckState(KMapColumnName, Qt::Unchecked);
		}
	}

	/* Enable check state change tracking after the tree has been filled */
	connect(m_mapTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
		this, SLOT(slotMapItemChanged(QTreeWidgetItem*)));
}