Ejemplo n.º 1
0
void AddFixture::fillTree()
{
	QPtrListIterator <QLCFixtureDef> it(*_app->fixtureDefList());
	QLCFixtureDef* fixtureDef = NULL;
	QListViewItem* parent = NULL;
	QListViewItem* node = NULL;
	QString str;

	/* Clear the tree of any previous data */
	m_tree->clear();

	/* Add all known fixture definitions. */
	while ( (fixtureDef = *it) != NULL )
	{
		parent = NULL;

		/* Search for an existing manufacturer parent node from
		   the tree. If such is found, it will be used as the
		   parent for the current fixture. If not, the manufacturer
		   will be added as a new parent and then used for the
		   current fixture. */
		for (node = m_tree->firstChild(); node != NULL;
		     node = node->nextSibling())
		{
			if (node->text(KColumnName) == fixtureDef->manufacturer())
			{
				parent = node;
				break;
			}
		}

		/* If an existing manufacturer parent node was not found,
		   we must create one. Otherwise we use the found node
		   as the parent for the new item. */
		if (parent == NULL)
			parent = new QListViewItem(m_tree,
						   fixtureDef->manufacturer());

		/* Create a new fixture node, under the parent node */
		node = new QListViewItem(parent);
		node->setText(KColumnName, fixtureDef->model());
		node->setText(KColumnType, fixtureDef->type());

		/* Store the fixture pointer into the tree */
		str.sprintf("%d", (unsigned long) fixtureDef);
		node->setText(KColumnPointer, str);

		++it;
	}

	/* Create a node & parent for generic dimmers */
	parent = new QListViewItem(m_tree);
	parent->setText(KColumnName, KXMLFixtureGeneric);
	node = new QListViewItem(parent);
	node->setText(KColumnName, KXMLFixtureGeneric);
	node->setText(KColumnType, KXMLFixtureDimmer);
	node->setText(KColumnPointer, "0");
}
Ejemplo n.º 2
0
void QLCFixtureDef_Test::manufacturer()
{
    QLCFixtureDef* fd = new QLCFixtureDef();
    fd->setManufacturer("Martin");
    QVERIFY(fd->manufacturer() == "Martin");
    QVERIFY(fd->name() == "Martin ");
    delete fd;
}
Ejemplo n.º 3
0
void QLCFixtureDef_Test::initial()
{
    QLCFixtureDef* fd = new QLCFixtureDef();
    QVERIFY(fd->manufacturer().isEmpty());
    QVERIFY(fd->model().isEmpty());
    QVERIFY(fd->name() == " ");
    QVERIFY(fd->type() == "Dimmer");
    delete fd;
}
Ejemplo n.º 4
0
QLCFixtureDef* QLCFixtureDefCache::fixtureDef(
    const QString& manufacturer, const QString& model) const
{
    QListIterator <QLCFixtureDef*> it(m_defs);
    while (it.hasNext() == true)
    {
        QLCFixtureDef* def = it.next();
        if (def->manufacturer() == manufacturer && def->model() == model)
        {
            def->checkLoaded(m_mapAbsolutePath);
            return def;
        }
    }

    return NULL;
}
Ejemplo n.º 5
0
QStringList QLCFixtureDefCache::models(const QString& manufacturer) const
{
    QSet <QString> models;
    QListIterator <QLCFixtureDef*> it(m_defs);
    while (it.hasNext() == true)
    {
        QLCFixtureDef* def = it.next();
        if (def->manufacturer() == manufacturer)
            models << def->model();
    }

    // Bounce the QSet into a QStringList
    QStringList list;
    foreach (QString model, models)
        list << model;

    return list;
}
Ejemplo n.º 6
0
void QLCFixtureDef_Test::saveLoadXML()
{
    const QString path("qlcfixturedef_test_saveXML.qxf");

    QLCFixtureDef* def = new QLCFixtureDef;
    def->setManufacturer("Foobar");
    def->setModel("Xyzzy");
    def->setType("Blinder");

    QLCChannel* ch = new QLCChannel;
    ch->setName("Whatever");
    def->addChannel(ch);

    QLCFixtureMode* mode = new QLCFixtureMode(def);
    mode->setName("Barfoo");
    def->addMode(mode);
    mode->insertChannel(ch, 0);

    QVERIFY(def->saveXML(QString("zxcvb:/path/to/nowhere") + path) != QFile::NoError);
    QCOMPARE(def->saveXML(path), QFile::NoError);

    // Test only QLCFixtureDef's doings and don't go into channel/mode details
    // since they are tested in their individual unit tests.
    QLCFixtureDef* def2 = new QLCFixtureDef;
    QCOMPARE(def2->loadXML(QString()), QFile::OpenError);
    QCOMPARE(def2->loadXML("/path/beyond/this/universe/foo.qxf"), QFile::ReadError);
    QCOMPARE(def2->loadXML("readonly.xml"), QFile::ReadError);

    QCOMPARE(def2->loadXML(path), QFile::NoError);
    QCOMPARE(def2->manufacturer(), def->manufacturer());
    QCOMPARE(def2->model(), def->model());
    QCOMPARE(def2->channels().size(), 1);
    QCOMPARE(def2->channels().at(0)->name(), ch->name());
    QCOMPARE(def2->modes().size(), 1);
    QCOMPARE(def2->modes().at(0)->name(), mode->name());

    delete def;
    delete def2;
    QFile::remove(path);
    QVERIFY(QFile::exists(path) == false);
}
Ejemplo n.º 7
0
void QLCFixtureDef_Test::copy()
{
    QLCFixtureDef* fd = new QLCFixtureDef();
    fd->setManufacturer("Martin");
    fd->setModel("MAC600");
    fd->setType("Moving Head");

    QLCChannel* ch = new QLCChannel();
    ch->setName("TestChannel");
    fd->addChannel(ch);

    QLCFixtureMode* mode = new QLCFixtureMode(fd);
    mode->setName("TestMode");
    fd->addMode(mode);
    mode->insertChannel(ch, 0);

    QLCFixtureDef* copy = new QLCFixtureDef(fd);
    QVERIFY(copy->manufacturer() == "Martin");
    QVERIFY(copy->model() == "MAC600");
    QVERIFY(copy->type() == "Moving Head");

    /* Verify that modes and channels get copied and that the channels in
       the copied mode are from the copied fixtureDef and not the one that
       the copy is taken FROM. */
    QVERIFY(copy->channels().at(0)->name() == "TestChannel");
    QVERIFY(copy->modes().at(0)->name() == "TestMode");
    QVERIFY(copy->modes().at(0)->channels().size() == 1);
    QVERIFY(copy->modes().size() == 1);
    QVERIFY(copy->modes().at(0)->channel(0) != ch);
    QVERIFY(copy->modes().at(0)->channel(0) == copy->channels().at(0));
    QVERIFY(copy->channels().at(0)->name() == "TestChannel");
    QVERIFY(copy->modes().at(0)->channel(0)->name() == "TestChannel");

    delete fd;
    delete copy;
}
Ejemplo n.º 8
0
void AddFixture_Test::initialScanner()
{
    Fixture* fxi = new Fixture(m_doc);
    fxi->setName("My scanner");

    QLCFixtureDef* def = m_doc->fixtureDefCache()->fixtureDef("Martin", "MAC300");
    Q_ASSERT(def != NULL);
    Q_ASSERT(def != NULL);
    Q_ASSERT(def->channels().size() > 0);
    QLCFixtureMode* mode = def->modes().first();
    Q_ASSERT(def->modes().size() > 1);

    fxi->setFixtureDefinition(def, mode);
    fxi->setUniverse(2);
    fxi->setAddress(484);
    m_doc->addFixture(fxi);

    AddFixture af(NULL, m_doc, fxi);
    QVERIFY(m_doc == af.m_doc);
    QVERIFY(af.fixtureDef() == def);
    QVERIFY(af.mode() == mode);
    QVERIFY(af.name() == QString("My scanner"));
    QVERIFY(af.address() == 484);
    QVERIFY(af.universe() == 2);
    QVERIFY(af.amount() == 1);
    QVERIFY(af.gap() == 0);
    QVERIFY(af.channels() == fxi->channels());

    // Check that all makes & models are put to the tree
    QStringList makers(m_doc->fixtureDefCache()->manufacturers());
    QVERIFY(makers.isEmpty() == false);
    for (int i = 0; i < af.m_tree->topLevelItemCount(); i++)
    {
        QTreeWidgetItem* top = af.m_tree->topLevelItem(i);

        if (top->text(0) != KXMLFixtureGeneric)
        {
            QStringList models(m_doc->fixtureDefCache()->models(top->text(0)));
            for (int j = 0; j < top->childCount(); j++)
            {
                QTreeWidgetItem* child = top->child(j);
                QCOMPARE(child->childCount(), 0);
                QCOMPARE(models.removeAll(child->text(0)), 1);
            }

            QCOMPARE(makers.removeAll(top->text(0)), 1);
        }
        else
        {
            QCOMPARE(i, af.m_tree->topLevelItemCount() - 1); // Generic should be last
            QCOMPARE(top->childCount(), 3);
            QCOMPARE(top->child(0)->text(0), QString(KXMLFixtureGeneric));

            QStringList models(m_doc->fixtureDefCache()->models(top->text(0)));
            for (int j = 0; j < top->childCount(); j++)
            {
                QTreeWidgetItem* child = top->child(j);
                QCOMPARE(child->childCount(), 0);
                QCOMPARE(models.removeAll(child->text(0)), child->text(0) == KXMLFixtureGeneric ? 0 : 1);
            }

            QCOMPARE(makers.removeAll(top->text(0)), 1);
        }
    }
    QVERIFY(makers.isEmpty() == true);

    // Generic / Generic should be selected for dimmers
    QVERIFY(af.m_tree->currentItem() != NULL);
    QCOMPARE(af.m_tree->currentItem()->text(0), def->model());
    QVERIFY(af.m_tree->currentItem()->parent() != NULL);
    QCOMPARE(af.m_tree->currentItem()->parent()->text(0), def->manufacturer());

    QVERIFY(af.m_modeCombo->isEnabled() == true);
    QCOMPARE(af.m_modeCombo->count(), def->modes().size());
    QCOMPARE(af.m_modeCombo->itemText(0), mode->name());

    QVERIFY(af.m_universeCombo->isEnabled() == true);
    QCOMPARE(af.m_universeCombo->currentIndex(), 2);
    QCOMPARE(af.m_universeCombo->count(), 4);

    QVERIFY(af.m_addressSpin->isEnabled() == true);
    QCOMPARE(af.m_addressSpin->value(), 485);

    QVERIFY(af.m_channelsSpin->isEnabled() == false);
    QCOMPARE(af.m_channelsSpin->value(), (int) fxi->channels());

    QVERIFY(af.m_nameEdit->isEnabled() == true);
    QCOMPARE(af.m_nameEdit->text(), QString("My scanner"));
    QVERIFY(af.m_nameEdit->isModified() == true);

    QVERIFY(af.m_multipleGroup->isEnabled() == false);
    QVERIFY(af.m_gapSpin->isEnabled() == false);
    QCOMPARE(af.m_gapSpin->value(), 0);

    QVERIFY(af.m_amountSpin->isEnabled() == false);
    QCOMPARE(af.m_amountSpin->value(), 1);
}