예제 #1
0
Score* NoteGroups::createScore(int n, TDuration::DurationType t, std::vector<Chord*>* chords)
      {
      MCursor c;
      c.setTimeSig(_sig);
      c.createScore("score8");
      c.addPart("voice");
      c.move(0, 0);
      c.addKeySig(0);
      TimeSig* nts = c.addTimeSig(_sig);
      GroupNode node {0, 0};
      Groups ng;
      ng.push_back(node);
      nts->setGroups(ng);

      for (int i = 0; i < n; ++i) {
            Chord* chord = c.addChord(67, t);
            int tick = chord->rtick();
            chord->setBeamMode(_groups.beamMode(tick, t));
            chords->push_back(chord);
            }

      c.score()->parts().front()->setLongName("");
      c.score()->style()->set(ST_linearStretch, 1.1);
      return c.score();
      }
예제 #2
0
void CVoxSQLite::InsertGroups( const char* username, Groups& rList )
{
	for ( Groups::iterator iter = rList.begin(); iter != rList.end(); iter++ )
	{
		InsertGroup( username, (*iter) );
	}
}
예제 #3
0
Score* NoteGroups::createScore(int n, TDuration::DurationType t, std::vector<Chord*>* chords)
      {
      MCursor c;
      c.setTimeSig(_sig);
      c.createScore("score8");
      c.addPart("voice");
      c.move(0, 0);
      c.addKeySig(Key::C);
      TimeSig* nts = c.addTimeSig(_sig);
      GroupNode node {0, 0};
      Groups ng;
      ng.push_back(node);
      nts->setGroups(ng);

      for (int i = 0; i < n; ++i) {
            Chord* chord = c.addChord(67, t);
            int tick = chord->rtick();
            chord->setBeamMode(_groups.beamMode(tick, t));
            chords->push_back(chord);
            }
      c.score()->pageFormat()->setEvenLeftMargin(0.0);
      c.score()->pageFormat()->setOddLeftMargin(0.0);

      c.score()->parts().front()->setLongName("");
      c.score()->style().set(StyleIdx::linearStretch, 1.3);
      c.score()->style().set(StyleIdx::MusicalSymbolFont, QString("Bravura"));
      c.score()->style().set(StyleIdx::MusicalTextFont, QString("Bravura Text"));
      return c.score();
      }
예제 #4
0
void gkGroupManager::attachGroupToScene(gkScene* scene, gkGameObjectGroup* group)
{
	class Listener : public gkResourceManager::ResourceListener
	{
	public:
		gkGroupManager* m_this;
	public:
		Listener(gkGroupManager* par) : m_this(par) {}

		virtual ~Listener() {}

		void notifyResourceDestroyed(gkResource* res)
		{
			if (gkGroupManager::getSingletonPtr())
				m_this->m_attachements.erase((gkScene*)res);
		}
	};

	if (!m_sceneListener)
	{
		m_sceneListener = new Listener(this);
		gkSceneManager::getSingleton().addResourceListener(m_sceneListener);
	}

	UTsize pos;
	if ((pos = m_attachements.find(scene)) != UT_NPOS)
		m_attachements.at(pos).push_back(group);
	else
	{
		Groups groups;
		groups.push_back(group);
		m_attachements.insert(scene, groups);
	}
}
예제 #5
0
TimeSigProperties::TimeSigProperties(TimeSig* t, QWidget* parent)
   : QDialog(parent)
      {
      setupUi(this);
      setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
      timesig = t;
      zText->setText(timesig->numeratorString());
      nText->setText(timesig->denominatorString());
      Fraction nominal = timesig->sig() * timesig->stretch();
      nominal.reduce();
      zNominal->setValue(nominal.numerator());
      nNominal->setValue(nominal.denominator());
      zActual->setValue(timesig->sig().numerator());
      nActual->setValue(timesig->sig().denominator());
      switch (timesig->timeSigType()) {
            case TSIG_NORMAL:
                  textButton->setChecked(true);
                  break;
            case TSIG_FOUR_FOUR:
                  fourfourButton->setChecked(true);
                  break;
            case TSIG_ALLA_BREVE:
                  allaBreveButton->setChecked(true);
                  break;
            }

      Groups g = t->groups();
      if (g.empty())
            g = Groups::endings(timesig->sig());     // initialize with default
      groups->setSig(timesig->sig(), g);
      }
/** Finds inferior cells, builds vcs. Sets moves to consider to all
    empty cells. If fillin causes terminal state, sets
    m_fillinCausedWin to true and recomputes fillin/vcs with ice
    temporarily turned off (so it can pass the players a non-empty
    consider set).
*/
HexPoint BenzenePlayer::InitSearch(HexBoard& brd, HexColor color, 
                                   bitset_t& consider, double& score)
{
    // Resign if the game is already over
    Groups groups;
    GroupBuilder::Build(brd.GetPosition(), groups);
    if (groups.IsGameOver()) 
    {
        score = IMMEDIATE_LOSS;
        return RESIGN;
    }
    StoneBoard original(brd.GetPosition());
    brd.ComputeAll(color);
    m_fillinCausedWin = false;
    m_fillinWinner = EMPTY;
    if (brd.GetGroups().IsGameOver()) 
    {
        // Fillin caused win, remove and re-compute without ice.
        m_fillinCausedWin = true;
        m_fillinWinner = brd.GetGroups().GetWinner();
        LogInfo() << "Captured cells caused win! Removing...\n";
        brd.GetPosition().SetPosition(original);
        bool oldUseIce = brd.UseICE();
        brd.SetUseICE(false);
        brd.ComputeAll(color);
        brd.SetUseICE(oldUseIce);
        BenzeneAssert(!brd.GetGroups().IsGameOver());
    } 
    consider = brd.GetPosition().GetEmpty();
    score = 0;
    return INVALID_POINT;
}
예제 #7
0
void TimeDialog::paletteChanged(int idx)
      {
      TimeSig* e = static_cast<TimeSig*>(sp->element(idx));
      if (!e || e->type() != Element::TIMESIG) {
            zNominal->setEnabled(false);
            nNominal->setEnabled(false);
            zText->setEnabled(false);
            nText->setEnabled(false);
            groups->setEnabled(false);
            addButton->setEnabled(false);
            return;
            }
      zNominal->setEnabled(true);
      nNominal->setEnabled(true);
      zText->setEnabled(true);
      nText->setEnabled(true);
      groups->setEnabled(true);
      addButton->setEnabled(true);

      Fraction sig(e->sig());
      Groups g = e->groups();
      if (g.empty())
            g = Groups::endings(sig);
      groups->setSig(sig, g);
      zNominal->setValue(sig.numerator());
      nNominal->setCurrentIndex(denominator2Idx(sig.denominator()));
      zText->setText(e->numeratorString());
      nText->setText(e->denominatorString());
      }
예제 #8
0
Groups NoteGroups::groups()
      {
      Groups g;
      for (Chord* chord : chords8)
            g.addStop(chord->rtick(), chord->durationType().type(), chord->beamMode());
      for (Chord* chord : chords16)
            g.addStop(chord->rtick(), chord->durationType().type(), chord->beamMode());
      for (Chord* chord : chords32)
            g.addStop(chord->rtick(), chord->durationType().type(), chord->beamMode());
      return g;
      }
void GroupBuilder::Build(const StoneBoard& brd, Groups& groups)
{
    bitset_t visited;
    groups.m_brd = const_cast<StoneBoard*>(&brd);
    groups.m_groups.clear();
    groups.m_group_index.resize(FIRST_INVALID);
    for (BoardIterator p(brd.Const().EdgesAndInterior()); p; ++p)
    {
        if (visited.test(*p))
            continue;
        bitset_t nbs, members;
        HexColor color = brd.GetColor(*p);
        Flow(brd, *p, color, members, nbs);
        HexAssert((visited & members).none());
        visited |= members;
        for (BitsetIterator m(members); m; ++m)
            groups.m_group_index[*m] = groups.m_groups.size();
        groups.m_groups.push_back(Group(&groups, color, *p, members, nbs));
    }
    for (std::size_t i = 0; i < groups.m_groups.size(); ++i)
    {
        Group& g = groups.m_groups[i];
        g.m_nbs = groups.CaptainizeBitset(g.m_nbs);
        for (BitsetIterator p(g.m_nbs); p; ++p)
            g.m_nbs_index.push_back(groups.m_group_index[*p]);
    }
}
예제 #10
0
void CVoxSQLite::GetGroups( const char* username, Groups& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from [Group] WHERE [username] = %Q;", username );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nContactId	= 0;
		std::string		type		= "";
		CppSQLite3Query q			= stmt.execQuery();
		Group			grp;

		//Process record set.
        while (!q.eof())
        {
			grp.setUsername( q.getStringField( 0 ) );
			grp.setName    ( q.getStringField( 1 ) );

			rList.Add( &grp );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
int XMLManager::SaveXML(string fileName, Components components, Groups groups){
    //創建檔案
    xmlFile.open(fileName.c_str(),ios::out);
    if(xmlFile.is_open()){
        AddComponentAndGroupToXMLFile(components.GetAllComponent(),groups.GetAllGroups());
        this->xmlFilePath = fileName; //把路徑記錄下來
         xmlFile.close();
        return XMLErrorCode::OK;
    }
    else{ //創建後如果無開啟 代表可能有錯誤
        xmlFile.close();
        return XMLErrorCode::Save_PathError;
    }
}
예제 #12
0
QVariant getProperty(P_ID id, XmlReader& e)
      {
      switch(propertyType(id)) {
            case P_TYPE::BOOL:
                  return QVariant(bool(e.readInt()));
            case P_TYPE::SUBTYPE:
            case P_TYPE::INT:
                  return QVariant(e.readInt());
            case P_TYPE::REAL:
            case P_TYPE::SPATIUM:
            case P_TYPE::SP_REAL:
            case P_TYPE::TEMPO:
                  return QVariant(e.readDouble());
            case P_TYPE::FRACTION:
                  return QVariant::fromValue(e.readFraction());
            case P_TYPE::COLOR:
                  return QVariant(e.readColor());
            case P_TYPE::POINT:
                  return QVariant(e.readPoint());
            case P_TYPE::SCALE:
            case P_TYPE::SIZE:
                  return QVariant(e.readSize());
            case P_TYPE::STRING:
                  return QVariant(e.readElementText());
            case P_TYPE::DIRECTION:
                  {
                  QString value(e.readElementText());
                  if (value == "up")
                        return QVariant(int(MScore::Direction::UP));
                  else if (value == "down")
                        return QVariant(int(MScore::Direction::DOWN));
                  else if (value == "auto")
                        return QVariant(int(MScore::Direction::AUTO));
                  }
                  break;
            case P_TYPE::DIRECTION_H:
                  {
                  QString value(e.readElementText());
                  if (value == "left" || value == "1")
                        return QVariant(int(MScore::DirectionH::LEFT));
                  else if (value == "right" || value == "2")
                        return QVariant(int(MScore::DirectionH::RIGHT));
                  else if (value == "auto")
                        return QVariant(int(MScore::DirectionH::AUTO));
                  }
                  break;
            case P_TYPE::LAYOUT_BREAK: {
                  QString value(e.readElementText());
                  if (value == "line")
                        return QVariant(int(LayoutBreak::Type::LINE));
                  if (value == "page")
                        return QVariant(int(LayoutBreak::Type::PAGE));
                  if (value == "section")
                        return QVariant(int(LayoutBreak::Type::SECTION));
                  qDebug("getProperty: invalid P_TYPE::LAYOUT_BREAK: <%s>", qPrintable(value));
                  }
                  break;
            case P_TYPE::VALUE_TYPE: {
                  QString value(e.readElementText());
                  if (value == "offset")
                        return QVariant(int(Note::ValueType::OFFSET_VAL));
                  else if (value == "user")
                        return QVariant(int(Note::ValueType::USER_VAL));
                  }
                  break;
            case P_TYPE::PLACEMENT: {
                  QString value(e.readElementText());
                  if (value == "above")
                        return QVariant(int(Element::Placement::ABOVE));
                  else if (value == "below")
                        return QVariant(int(Element::Placement::BELOW));
                  }
                  break;
            case P_TYPE::BEAM_MODE:             // TODO
                  return QVariant(int(0));

            case P_TYPE::GROUPS:
                  {
                  Groups g;
                  g.read(e);
                  return QVariant::fromValue(g);
                  }
            case P_TYPE::POINT_MM:
            case P_TYPE::SIZE_MM:
            case P_TYPE::SYMID:
            case P_TYPE::TEXT_STYLE:
                  return QVariant();
            }
      return QVariant();
      }
예제 #13
0
QVariant getProperty(P_ID id, XmlReader& e)
      {
      switch (propertyType(id)) {
            case P_TYPE::BOOL:
                  return QVariant(bool(e.readInt()));
            case P_TYPE::SUBTYPE:
            case P_TYPE::INT:
                  return QVariant(e.readInt());
            case P_TYPE::REAL:
            case P_TYPE::SPATIUM:
            case P_TYPE::SP_REAL:
            case P_TYPE::TEMPO:
                  return QVariant(e.readDouble());
            case P_TYPE::FRACTION:
                  return QVariant::fromValue(e.readFraction());
            case P_TYPE::COLOR:
                  return QVariant(e.readColor());
            case P_TYPE::POINT:
                  return QVariant(e.readPoint());
            case P_TYPE::SCALE:
            case P_TYPE::SIZE:
                  return QVariant(e.readSize());
            case P_TYPE::STRING:
                  return QVariant(e.readElementText());
            case P_TYPE::GLISSANDO_STYLE: {
                  QString value(e.readElementText());
                  if ( value == "whitekeys")
                        return QVariant(int(MScore::GlissandoStyle::WHITE_KEYS));
                  else if ( value == "blackkeys")
                        return QVariant(int(MScore::GlissandoStyle::BLACK_KEYS));
                  else if ( value == "diatonic")
                        return QVariant(int(MScore::GlissandoStyle::DIATONIC));
                  else // e.g., normally "Chromatic"
                        return QVariant(int(MScore::GlissandoStyle::CHROMATIC));
                  }
                  break;
            case P_TYPE::ORNAMENT_STYLE: {
                  QString value(e.readElementText());
                  if ( value == "baroque")
                        return QVariant(int(MScore::OrnamentStyle::BAROQUE));
                  return QVariant(int(MScore::OrnamentStyle::DEFAULT));
                  }

            case P_TYPE::DIRECTION:
                  return QVariant::fromValue(Direction(e.readElementText()));

            case P_TYPE::DIRECTION_H:
                  {
                  QString value(e.readElementText());
                  if (value == "left" || value == "1")
                        return QVariant(int(MScore::DirectionH::LEFT));
                  else if (value == "right" || value == "2")
                        return QVariant(int(MScore::DirectionH::RIGHT));
                  else if (value == "auto")
                        return QVariant(int(MScore::DirectionH::AUTO));
                  }
                  break;
            case P_TYPE::LAYOUT_BREAK: {
                  QString value(e.readElementText());
                  if (value == "line")
                        return QVariant(int(LayoutBreak::Type::LINE));
                  if (value == "page")
                        return QVariant(int(LayoutBreak::Type::PAGE));
                  if (value == "section")
                        return QVariant(int(LayoutBreak::Type::SECTION));
                  qDebug("getProperty: invalid P_TYPE::LAYOUT_BREAK: <%s>", qPrintable(value));
                  }
                  break;
            case P_TYPE::VALUE_TYPE: {
                  QString value(e.readElementText());
                  if (value == "offset")
                        return QVariant(int(Note::ValueType::OFFSET_VAL));
                  else if (value == "user")
                        return QVariant(int(Note::ValueType::USER_VAL));
                  }
                  break;
            case P_TYPE::PLACEMENT: {
                  QString value(e.readElementText());
                  if (value == "above")
                        return QVariant(int(Element::Placement::ABOVE));
                  else if (value == "below")
                        return QVariant(int(Element::Placement::BELOW));
                  }
                  break;
            case P_TYPE::BARLINE_TYPE: {
                  bool ok;
                  const QString& val(e.readElementText());
                  int ct = val.toInt(&ok);
                  if (ok)
                        return QVariant(ct);
                  else {
                        BarLineType t = BarLine::barLineType(val);
                        return QVariant::fromValue(t);
                        }
                  }
                  break;
            case P_TYPE::BEAM_MODE:             // TODO
                  return QVariant(int(0));

            case P_TYPE::GROUPS:
                  {
                  Groups g;
                  g.read(e);
                  return QVariant::fromValue(g);
                  }
            case P_TYPE::POINT_MM:              // not supported
            case P_TYPE::TDURATION:
            case P_TYPE::SIZE_MM:
            case P_TYPE::SYMID:
            case P_TYPE::TEXT_STYLE:
            case P_TYPE::INT_LIST:
                  return QVariant();
            }
      return QVariant();
      }
bool GameUtil::IsGameOver(const Game& game)
{
    Groups groups;
    GroupBuilder::Build(game.Board(), groups);
    return groups.IsGameOver();
}
예제 #15
0
TimeSigProperties::TimeSigProperties(TimeSig* t, QWidget* parent)
    : QDialog(parent)
{
    setupUi(this);
    setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    timesig = t;

    zText->setText(timesig->numeratorString());
    nText->setText(timesig->denominatorString());
    // set validators for numerator and denominator strings
    // which only accept '+', '(', ')', digits and some time symb conventional representations
    QRegExp rx("[0-9+CO()\\x00A2\\x00D8]*");
    QValidator *validator = new QRegExpValidator(rx, this);
    zText->setValidator(validator);
    nText->setValidator(validator);

    Fraction nominal = timesig->sig() / timesig->stretch();
    nominal.reduce();
    zNominal->setValue(nominal.numerator());
    nNominal->setValue(nominal.denominator());
    Fraction sig(timesig->sig());
    zActual->setValue(sig.numerator());
    nActual->setValue(sig.denominator());
    zNominal->setEnabled(false);
    nNominal->setEnabled(false);

    // TODO: fix http://musescore.org/en/node/42341
    // for now, editing of actual (local) time sig is disabled in dialog
    // but more importantly, the dialog should make it clear that this is "local" change only
    // and not normally the right way to add 7/4 to a score
    zActual->setEnabled(false);
    nActual->setEnabled(false);
    switch (timesig->timeSigType()) {
    case TimeSigType::NORMAL:
        textButton->setChecked(true);
        break;
    case TimeSigType::FOUR_FOUR:
        fourfourButton->setChecked(true);
        break;
    case TimeSigType::ALLA_BREVE:
        allaBreveButton->setChecked(true);
        break;
    }

    // set ID's of other symbols
    static const SymId prolatioSymbols[] = {
        SymId::mensuralProlation1,          // tempus perfectum, prol. perfecta
        SymId::mensuralProlation2,          // tempus perfectum, prol. imperfecta
        SymId::mensuralProlation3,          // tempus perfectum, prol. imperfecta, dimin.
        SymId::mensuralProlation4,          // tempus perfectum, prol. perfecta, dimin.
        SymId::mensuralProlation5,          // tempus imperf. prol. perfecta
//            SymId::mensuralProlation6,              // same shape as common time
        SymId::mensuralProlation7,          // tempus imperf., prol. imperfecta, reversed
        SymId::mensuralProlation8,          // tempus imperf., prol. perfecta, dimin.
//            SymId::mensuralProlation9,              // same shape as alla breve
        SymId::mensuralProlation10,         // tempus imperf., prol imperfecta, dimin., reversed
        SymId::mensuralProlation11,         // tempus inperf., prol. perfecta, reversed
    };

    ScoreFont* scoreFont = t->score()->scoreFont();
    int idx = 0;
    for (SymId symId : prolatioSymbols) {
        const QString& str = scoreFont->toString(symId);
        if (str.size() > 0) {
            otherCombo->setItemData(idx, (int)symId);
            // if time sig matches this symbol string, set as selected
            if (timesig->timeSigType() == TimeSigType::NORMAL && timesig->denominatorString().isEmpty()
                    && timesig->numeratorString() == str) {
                textButton->setChecked(false);
                otherButton->setChecked(true);
                otherCombo->setCurrentIndex(idx);
            }
        }
        idx++;
    }

    Groups g = t->groups();
    if (g.empty())
        g = Groups::endings(timesig->sig());     // initialize with default
    groups->setSig(timesig->sig(), g);
}
예제 #16
0
 actor spawn_in_groups(const Groups& gs, F fun, Ts&&... xs) {
   actor_config cfg{context()};
   return eval_opts(Os, system().spawn_in_groups_impl<make_unbound(Os)>(cfg, gs.begin(), gs.end(), fun, std::forward<Ts>(xs)...));
 }
예제 #17
0
void WorkSheetModel::generateData(const bool &cancelLoad)
{
    static int numOfLineChecksCalled = 0;
    static int numOfLines = 250;
    QString name;
    QString mbName;
    QMessage   *qmessage;
    Message    *message;
    MessageBase *header;
    MessageBase *trailer;
    BaseField  *baseField;
    QBaseEntry *tableHeader;
    GroupBase  *groupBase;
    FieldTrait::FieldType ft;
    char c[60];
    int fieldID;
    int rowPos = 0;
    int colPos = 0;
    quint32 sortRole = Qt::UserRole + 2;
    setSortRole(sortRole);
    setRowCount(0);

    if (!tableSchema) {
        qWarning() << "Unable to generate data -  table schema is null" << __FILE__ << __LINE__;
        return;
    }
    if (!tableSchema->fieldList) {
        qWarning() << "Unable to generate data -  field list is null" << __FILE__ << __LINE__;
        setColumnCount(0);
        return;
    }
    if (!messageList) {
        qWarning() << "Unable to generate data -  message list is null" << __FILE__ << __LINE__;
        return;
    }

    setColumnCount(tableSchema->fieldList->count());
    QColor modBGColor; // = QColor(255,214,79,100);
    // This is a list of messages read in from file
    QListIterator <QMessage *> mIter(*messageList);
    // this is the fields user selected that they want displayed
    QListIterator <QBaseEntry *> tableHeaderIter(*(tableSchema->fieldList));
    bool modifyBackgroundColor;
    QElapsedTimer myTimer;
    myTimer.start();
    int messageCount = messageList->count();
    //setRowCount(messageCount);

    while(mIter.hasNext()) {
        if ((rowPos%numOfLines) == 0) { // every 100 iterations allow gui to process events
            numOfLineChecksCalled++;
            if (numOfLineChecksCalled > 5)
                numOfLines = 1000;
            if (cancelLoad) {
                qDebug() << "CANCEL LOAD IN GENERATE DATA " << __FILE__ << __LINE__;
                return;
            }
            /*
            WorkSheet *w = qobject_cast <WorkSheet *> (parent());
            if (w) {
                w->setUpdatesEnabled(true);
                w->updateTable();
                w->update();
                qApp->processEvents(QEventLoop::WaitForMoreEvents,100);

                w->setUpdatesEnabled(false);
            }
            */
        }
        qmessage = mIter.next();
        QString senderID = qmessage->senderID;
        //qDebug() << ">>>>>>>>>>>>> MESSAGE LIST COUNT = " << messageList->count() << __FILE__ << __LINE__;
        // qDebug() << "Look for sender id = " << senderID << __FILE__ << __LINE__;
        if (messageList->senderColorMap.contains(qmessage->senderID) ) {
            modBGColor =messageList->senderColorMap.value(qmessage->senderID);
            modifyBackgroundColor = true;
        }
        else
            modifyBackgroundColor = false;
        QVariant var;
        var.setValue((void *) qmessage);
        message  = qmessage->mesg;
        header = message->Header();
        trailer = message->Trailer();
        tableHeaderIter.toFront();
        colPos = 0;
        bool found;
        QList <QStandardItem *>items;
        while(tableHeaderIter.hasNext()) {
            found = false;
            tableHeader = tableHeaderIter.next();
            fieldID = tableHeader->ft->_fnum;
            if (header) {
                BaseField *bf = header->get_field(fieldID);
                if (bf) {
                    ft =  bf->get_underlying_type();
                    memset(c,'\0',60);
                    bf->print(c);
                    if (FieldTrait::is_int(ft)) {
                        int ival(static_cast<Field<int, 0>*>(bf)->get());
                        //qDebug() << tableHeader->name << ", field id = " << fieldID << ", value = " << ival;
                        IntItem *intItem = new IntItem(ival);
                        //QStandardItem *intItem = new QStandardItem(QString::number(ival));

                        //intItem->setData(ival,Qt::UserRole);
                        intItem->setData(senderID,senderIDRole);
                        intItem->setData(var);
                        intItem->setData(ival,sortRole);
                        if (modifyBackgroundColor)
                            intItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,intItem);
                        items.append(intItem);
                        found = true;
                    }

                    else if (FieldTrait::is_float(ft)) {
                        qDebug() << "WORK WITH FLOAT" << __FILE__ << __LINE__;
                        double fval(static_cast<Field<double, 0>*>(bf)->get());
                        found = true;

                    }

                    else if (FieldTrait::is_string(ft)) {
                        memset(c,'\0',60);
                        bf->print(c);
                        QLatin1Literal ll(c);
                        QStandardItem *strItem = new QStandardItem(QString(ll));
                        strItem->setData(senderID,senderIDRole);
                        strItem->setData(var);
                        strItem->setData(ll,sortRole);
                        if (modifyBackgroundColor)
                            strItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,strItem);
                        items.append(strItem);

                        found = true;

                    }
                    else if (FieldTrait::is_char(ft)) {
                        QChar ch(static_cast<Field<char, 0>*>(bf)->get());
                        QString cstr = ch.decomposition();
                        QStandardItem *charItem = new QStandardItem(cstr);
                        charItem->setData(senderID,senderIDRole);
                        charItem->setData(var);
                        charItem->setData(cstr,sortRole);
                        if (modifyBackgroundColor)
                            charItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,charItem);
                        items.append(charItem);

                        found = true;

                    }

                }
            }
            if (message) {
                BaseField *bfm = message->get_field(fieldID);
                if (bfm) {
                    ft =  bfm->get_underlying_type();
                    memset(c,'\0',60);
                    bfm->print(c);
                    if (FieldTrait::is_int(ft)) {
                        int ival(static_cast<Field<int, 0>*>(bfm)->get());
                        //qDebug() << tableHeader->name << ", field id = " << fieldID << ", value = " << ival;
                        IntItem *intItem = new IntItem(ival);
                        intItem->setData(senderID,senderIDRole);
                        intItem->setData(var);
                        intItem->setData(ival,sortRole);
                        if (modifyBackgroundColor)
                            intItem->setData(modBGColor, Qt::BackgroundRole);
                        // setItem(rowPos,colPos,intItem);
                        items.append(intItem);

                        found = true;

                    }
                    else if (FieldTrait::is_float(ft)) {
                        qDebug() << "WORK WITH FLOAT" << __FILE__ << __LINE__;
                        double fval(static_cast<Field<double, 0>*>(bfm)->get());
                        found = true;
                    }

                    else if (FieldTrait::is_string(ft)) {
                        memset(c,'\0',60);
                        bfm->print(c);
                        QStandardItem *strItem = new QStandardItem(QLatin1Literal(c));
                        strItem->setData(senderID,senderIDRole);
                        strItem->setData(QLatin1Literal(c),sortRole);
                        strItem->setData(var);
                        if (modifyBackgroundColor)
                            strItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,strItem);
                        items.append(strItem);

                        found = true;
                    }
                    else if (FieldTrait::is_char(ft)) {
                        QChar ch(static_cast<Field<char, 0>*>(bfm)->get());
                        QString cstr = ch.decomposition();
                        QStandardItem *charItem = new QStandardItem(cstr);
                        charItem->setData(senderID,senderIDRole);
                        charItem->setData(cstr,sortRole);
                        charItem->setData(var);
                        if (modifyBackgroundColor)
                            charItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,charItem);
                        items.append(charItem);

                        found = true;
                    }
                }

                //else
                //   qWarning() << "BASE FIELD = NULL FOR HEADER" << __FILE__ << __LINE__;
                Groups groups = message->get_groups();
                std::map<unsigned short,GroupBase *>::iterator iterGrps;
                for(iterGrps = groups.begin(); iterGrps != groups.end(); iterGrps++) {
                    groupBase = iterGrps->second;
                    int size = groupBase->size();
                    for(int i=0;i<size;i++) {
                        MessageBase *mb = groupBase->get_element(i);
                        mbName = QString::fromStdString(mb->get_msgtype());
                        BaseField *bfg = mb->get_field(fieldID);
                        if (bfg) {
                            ft =  bfg->get_underlying_type();
                            memset(c,'\0',60);
                            bfg->print(c);
                            if (FieldTrait::is_int(ft)) {
                                int ival(static_cast<Field<int, 0>*>(bfg)->get());
                                //qDebug() << tableHeader->name << ", field id = " << fieldID << ", value = " << ival;
                                IntItem *intItem = new IntItem(ival);
                                intItem->setData(senderID,senderIDRole);
                                intItem->setData(ival,sortRole);
                                intItem->setData(var);
                                if (modifyBackgroundColor)
                                    intItem->setData(modBGColor, Qt::BackgroundRole);
                                //setItem(rowPos,colPos,intItem);
                                items.append(intItem);

                                found = true;
                            }
                            else if (FieldTrait::is_float(ft)) {
                                qDebug() << "WORK WITH FLOAT" << __FILE__ << __LINE__;
                                double fval(static_cast<Field<double, 0>*>(bfg)->get());
                                found = true;
                            }
                            else if (FieldTrait::is_string(ft)) {
                                memset(c,'\0',60);
                                bfg->print(c);
                                QStandardItem *strItem = new QStandardItem(QLatin1Literal(c));
                                strItem->setData(senderID,senderIDRole);
                                strItem->setData(QLatin1Literal(c),sortRole);
                                strItem->setData(var);
                                if (modifyBackgroundColor)
                                    strItem->setData(modBGColor, Qt::BackgroundRole);
                                //setItem(rowPos,colPos,strItem);
                                items.append(strItem);

                                found = true;
                            }
                            else if (FieldTrait::is_char(ft)) {
                                QChar ch(static_cast<Field<char, 0>*>(bfm)->get());
                                QString cstr = ch.decomposition();
                                QStandardItem *charItem = new QStandardItem(cstr);
                                charItem->setData(senderID,senderIDRole);
                                charItem->setData(cstr,sortRole);
                                charItem->setData(var);
                                if (modifyBackgroundColor)
                                    charItem->setData(modBGColor, Qt::BackgroundRole);
                                // setItem(rowPos,colPos,charItem);
                                items.append(charItem);

                                found = true;
                            }
                        }
                        //  else
                        //     qWarning() << "BASE FIELD = NULL FOR GROUP" << __FILE__ << __LINE__;
                        // qDebug() << "\t\tHave Message Named: " + mbName;
                    }
                }
            }
            if (trailer) {
                BaseField *bft = trailer->get_field(fieldID);
                if (bft) {
                    ft =  bft->get_underlying_type();
                    memset(c,'\0',60);
                    bft->print(c);
                    if (FieldTrait::is_int(ft)) {
                        int ival(static_cast<Field<int, 0>*>(bft)->get());
                        IntItem *intItem = new IntItem(ival);
                        intItem->setData(senderID,senderIDRole);
                        intItem->setData(ival,sortRole);
                        intItem->setData(var);
                        if (modifyBackgroundColor)
                            intItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,intItem);
                        items.append(intItem);

                        found = true;
                    }
                    else if (FieldTrait::is_float(ft)) {
                        qDebug() << "WORK WITH FLOAT" << __FILE__ << __LINE__;
                        double fval(static_cast<Field<double, 0>*>(bft)->get());
                        found = true;
                    }
                    else if (FieldTrait::is_string(ft)) {
                        memset(c,'\0',60);
                        bft->print(c);
                        QStandardItem *strItem = new QStandardItem(QLatin1Literal(c));
                        strItem->setData(senderID,senderIDRole);
                        strItem->setData(var);
                        strItem->setData(QLatin1Literal(c),sortRole);
                        if (modifyBackgroundColor)
                            strItem->setData(modBGColor, Qt::BackgroundRole);
                        //setItem(rowPos,colPos,strItem);
                        items.append(strItem);

                        found = true;
                    }
                    else if (FieldTrait::is_char(ft)) {
                        QChar ch(static_cast<Field<char, 0>*>(bft)->get());
                        QString cstr = ch.decomposition();
                        QStandardItem *charItem = new QStandardItem(cstr);
                        charItem->setData(senderID,senderIDRole);
                        charItem->setData(var);
                        charItem->setData(cstr,sortRole);
                        if (modifyBackgroundColor)
                            charItem->setData(modBGColor, Qt::BackgroundRole);
                        // setItem(rowPos,colPos,charItem);
                        items.append(charItem);

                        found = true;
                    }
                }
                //else
                // qWarning() << "BASE FIELD = NULL FOR TRAILER"  << __FILE__ << __LINE__;
            }
            if (!found) {
                //qDebug() << "**************** NOT FOUND **********************" << colPos << __FILE__ << __LINE__;
                // create a dummmy item, so color of row can be uniform across;
                QStandardItem *dummyItem = new QStandardItem("");
                dummyItem->setData(senderID,senderIDRole);
                dummyItem->setData(var);
                if (modifyBackgroundColor)
                    dummyItem->setData(modBGColor, Qt::BackgroundRole);
                //setItem(rowPos,colPos,dummyItem);
                items.append(dummyItem);

            }
            colPos++;
        }
        appendRow(items);
        rowPos++;
    }
    int nMilliseconds = myTimer.elapsed();
    //qDebug() << "TIME TO LOAD = " << nMilliseconds;
}
bool MLogicalValuesPrivate::parse(const QFileInfo &fileInfo, Groups &groups)
{
    QFile file(fileInfo.filePath());
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    QByteArray group = "General";
    groups.insert("General", Values());

    while (!file.atEnd()) {
        QByteArray line = file.readLine().trimmed();
        // skip comments
        if (line.startsWith("[")) {
            // parse group header
            int index = line.indexOf("]", 1);
            if (index == -1) {
                mWarning("MLogicalValues") << "Error occurred when parsing .ini file:" << line;
                file.close();
                return false;
            }
            // this will be the currently active group
            group = line.mid(1, index - 1);
        } else {

            // key/value pair
            QByteArray key, value;
            QByteArray *target = &key;

            // stores the last 'good' character
            int truncation = 0;
            // go through whole line
            for (int i = 0; i < line.length(); i++) {
                QChar character = line.at(i);
                if (character == ';') {
                    break;
                } else if (character == '=') {
                    // remove trailing whitespaces
                    target->truncate(truncation);
                    // start to parse value
                    target = &value;
                    truncation = 0;
                } else {
                    if (target->isEmpty() && character.isSpace()) {
                        // do not add whitespaces at the beginning
                    } else {
                        (*target) += character;
                        if (!character.isSpace())
                            truncation = target->length();
                    }
                }
            }
            // remove trailing whitespaces
            target->truncate(truncation);

            // consistency check
            if (!line.startsWith(';') && line.length() > 0) {
                if (key.isEmpty() || value.isEmpty()) {
                    mWarning("MLogicalValues") << "Error occurred when parsing .ini file:" << line;
                    file.close();
                    return false;
                }
                // store
                Values &values = groups[group];

                if (!values.contains(key)) {
                    values.insert(key, value);
                }
            }
        }
    }

    saveToBinaryCache(fileInfo, groups);
    file.close();
    return true;
}
예제 #19
0
QVariant getProperty(P_ID id, XmlReader& e)
      {
      switch (propertyType(id)) {
            case P_TYPE::BOOL:
                  return QVariant(bool(e.readInt()));
            case P_TYPE::SUBTYPE:
            case P_TYPE::ZERO_INT:
            case P_TYPE::INT:
                  return QVariant(e.readInt());
            case P_TYPE::REAL:
            case P_TYPE::SPATIUM:
            case P_TYPE::SP_REAL:
            case P_TYPE::TEMPO:
                  return QVariant(e.readDouble());
            case P_TYPE::FRACTION:
                  return QVariant::fromValue(e.readFraction());
            case P_TYPE::COLOR:
                  return QVariant(e.readColor());
            case P_TYPE::POINT:
                  return QVariant(e.readPoint());
            case P_TYPE::SCALE:
            case P_TYPE::SIZE:
                  return QVariant(e.readSize());
            case P_TYPE::FONT:
            case P_TYPE::STRING:
                  return QVariant(e.readElementText());
            case P_TYPE::GLISSANDO_STYLE: {
                  QString value(e.readElementText());
                  if ( value == "whitekeys")
                        return QVariant(int(MScore::GlissandoStyle::WHITE_KEYS));
                  else if ( value == "blackkeys")
                        return QVariant(int(MScore::GlissandoStyle::BLACK_KEYS));
                  else if ( value == "diatonic")
                        return QVariant(int(MScore::GlissandoStyle::DIATONIC));
                  else // e.g., normally "Chromatic"
                        return QVariant(int(MScore::GlissandoStyle::CHROMATIC));
                  }
                  break;
            case P_TYPE::ORNAMENT_STYLE: {
                  QString value(e.readElementText());
                  if ( value == "baroque")
                        return QVariant(int(MScore::OrnamentStyle::BAROQUE));
                  return QVariant(int(MScore::OrnamentStyle::DEFAULT));
                  }

            case P_TYPE::DIRECTION:
                  return QVariant::fromValue(Direction(e.readElementText()));

            case P_TYPE::DIRECTION_H:
                  {
                  QString value(e.readElementText());
                  if (value == "left" || value == "1")
                        return QVariant(int(MScore::DirectionH::LEFT));
                  else if (value == "right" || value == "2")
                        return QVariant(int(MScore::DirectionH::RIGHT));
                  else if (value == "auto")
                        return QVariant(int(MScore::DirectionH::AUTO));
                  }
                  break;
            case P_TYPE::LAYOUT_BREAK: {
                  QString value(e.readElementText());
                  if (value == "line")
                        return QVariant(int(LayoutBreak::LINE));
                  if (value == "page")
                        return QVariant(int(LayoutBreak::PAGE));
                  if (value == "section")
                        return QVariant(int(LayoutBreak::SECTION));
                  if (value == "nobreak")
                        return QVariant(int(LayoutBreak::NOBREAK));
                  qDebug("getProperty: invalid P_TYPE::LAYOUT_BREAK: <%s>", qPrintable(value));
                  }
                  break;
            case P_TYPE::VALUE_TYPE: {
                  QString value(e.readElementText());
                  if (value == "offset")
                        return QVariant(int(Note::ValueType::OFFSET_VAL));
                  else if (value == "user")
                        return QVariant(int(Note::ValueType::USER_VAL));
                  }
                  break;
            case P_TYPE::PLACEMENT: {
                  QString value(e.readElementText());
                  if (value == "above")
                        return QVariant(int(Element::Placement::ABOVE));
                  else if (value == "below")
                        return QVariant(int(Element::Placement::BELOW));
                  }
                  break;
            case P_TYPE::BARLINE_TYPE: {
                  bool ok;
                  const QString& val(e.readElementText());
                  int ct = val.toInt(&ok);
                  if (ok)
                        return QVariant(ct);
                  else {
                        BarLineType t = BarLine::barLineType(val);
                        return QVariant::fromValue(t);
                        }
                  }
                  break;
            case P_TYPE::BEAM_MODE:             // TODO
                  return QVariant(int(0));

            case P_TYPE::GROUPS:
                  {
                  Groups g;
                  g.read(e);
                  return QVariant::fromValue(g);
                  }
            case P_TYPE::SYMID:
                  return QVariant::fromValue(Sym::name2id(e.readElementText()));
                  break;
            case P_TYPE::HEAD_GROUP:
                  return QVariant::fromValue(NoteHead::name2group(e.readElementText()));;
            case P_TYPE::HEAD_TYPE:
                  return QVariant::fromValue(NoteHead::name2type(e.readElementText()));
            case P_TYPE::POINT_MM:              // not supported
            case P_TYPE::TDURATION:
            case P_TYPE::SIZE_MM:
            case P_TYPE::TEXT_STYLE:
            case P_TYPE::INT_LIST:
                  return QVariant();
            case P_TYPE::SUB_STYLE:
                  return int(subStyleFromName(e.readElementText()));
            case P_TYPE::ALIGN: {
                  QString s = e.readElementText();
                  QStringList sl = s.split(',');
                  if (sl.size() != 2) {
                        qDebug("bad align text <%s>", qPrintable(s));
                        return QVariant();
                        }
                  Align align = Align::LEFT;
                  if (sl[0] == "center")
                        align = align | Align::HCENTER;
                  else if (sl[0] == "right")
                        align = align | Align::RIGHT;
                  else if (sl[0] == "left")
                        ;
                  else {
                        qDebug("bad align text <%s>", qPrintable(sl[0]));
                        return QVariant();
                        }
                  if (sl[1] == "center")
                        align = align | Align::VCENTER;
                  else if (sl[1] == "bottom")
                        align = align | Align::BOTTOM;
                  else if (sl[1] == "baseline")
                        align = align | Align::BASELINE;
                  else if (sl[1] == "top")
                        ;
                  else {
                        qDebug("bad align text <%s>", qPrintable(sl[1]));
                        return QVariant();
                        }
                  return  int(align);
                  }
            default:
                  qFatal("unhandled PID type");
                  break;
            }
      return QVariant();
      }
예제 #20
0
TimeSigProperties::TimeSigProperties(TimeSig* t, QWidget* parent)
   : QDialog(parent)
      {
      setupUi(this);
      setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
      timesig = t;

      zText->setText(timesig->numeratorString());
      nText->setText(timesig->denominatorString());
      // set validators for numerator and denominator strings
      // which only accept '+', '(', ')' and digits
      QRegExp rx("[0-9+()]*");
      QValidator *validator = new QRegExpValidator(rx, this);
      zText->setValidator(validator);
      nText->setValidator(validator);

      Fraction nominal = timesig->sig() * timesig->stretch();
      nominal.reduce();
      zNominal->setValue(nominal.numerator());
      nNominal->setValue(nominal.denominator());
      zActual->setValue(timesig->sig().numerator());
      nActual->setValue(timesig->sig().denominator());
      switch (timesig->timeSigType()) {
            case TSIG_NORMAL:
                  textButton->setChecked(true);
                  break;
            case TSIG_FOUR_FOUR:
                  fourfourButton->setChecked(true);
                  break;
            case TSIG_ALLA_BREVE:
                  allaBreveButton->setChecked(true);
                  break;
            }

      // set ID's of other symbols
      static const SymId prolatioSymbols[] = {
            SymId::mensuralTempPerfProlPerf,
            SymId::mensuralTempPerfProlImp,
            SymId::mensuralTempPerfProlImpDimin,
            SymId::mensuralTempPerfProlPerfDimin,
            SymId::mensuralTempImpProlPerf,
//            SymId::mensuralTempImpProlImp,          // same shape as common time
            SymId::mensuralTempImpProlImpRev,
            SymId::mensuralTempImpProlPerfDimin,
//            SymId::mensuralTempImpProlImpDimin,     // same shape as alla breve
            SymId::mensuralTempImpProlImpDiminRev,
            SymId::mensuralTempImpProlPerfRev,
            };

      ScoreFont* scoreFont = t->score()->scoreFont();
      int idx = 0;
      for (SymId symId : prolatioSymbols) {
            const QString& str = scoreFont->toString(symId);
            if (str.size() > 0) {
                  otherCombo->setItemData(idx, (int)symId);
                  // if time sig matches this symbol string, set as selected
                  if (timesig->timeSigType() == TSIG_NORMAL && timesig->denominatorString().isEmpty()
                  && timesig->numeratorString() == str) {
                        textButton->setChecked(false);
                        otherButton->setChecked(true);
                        otherCombo->setCurrentIndex(idx);
                        }
                  }
            idx++;
            }

      Groups g = t->groups();
      if (g.empty())
            g = Groups::endings(timesig->sig());     // initialize with default
      groups->setSig(timesig->sig(), g);
      }
예제 #21
0
QVariant getProperty(P_ID id, XmlReader& e)
      {
      switch(propertyType(id)) {
            case T_BOOL:
                  return QVariant(bool(e.readInt()));
            case T_SUBTYPE:
            case T_INT:
                  return QVariant(e.readInt());
            case T_REAL:
            case T_SPATIUM:
            case T_SP_REAL:
            case T_TEMPO:
                  return QVariant(e.readDouble());
            case T_FRACTION:
                  return QVariant::fromValue(e.readFraction());
            case T_COLOR:
                  return QVariant(e.readColor());
            case T_POINT:
                  return QVariant(e.readPoint());
            case T_SCALE:
            case T_SIZE:
                  return QVariant(e.readSize());
            case T_STRING:
                  return QVariant(e.readElementText());
            case T_DIRECTION:
                  {
                  QString value(e.readElementText());
                  if (value == "up")
                        return QVariant(MScore::UP);
                  else if (value == "down")
                        return QVariant(MScore::DOWN);
                  else if (value == "auto")
                        return QVariant(MScore::AUTO);
                  }
                  break;
            case T_DIRECTION_H:
                  {
                  QString value(e.readElementText());
                  if (value == "left")
                        return QVariant(MScore::DH_LEFT);
                  else if (value == "right")
                        return QVariant(MScore::DH_RIGHT);
                  else if (value == "auto")
                        return QVariant(MScore::DH_AUTO);
                  }
                  break;
            case T_LAYOUT_BREAK: {
                  QString value(e.readElementText());
                  if (value == "line")
                        return QVariant(int(LAYOUT_BREAK_LINE));
                  if (value == "page")
                        return QVariant(int(LAYOUT_BREAK_PAGE));
                  if (value == "section")
                        return QVariant(int(LAYOUT_BREAK_SECTION));
                  qDebug("getProperty: invalid T_LAYOUT_BREAK: <%s>", qPrintable(value));
                  }
                  break;
            case T_VALUE_TYPE: {
                  QString value(e.readElementText());
                  if (value == "offset")
                        return QVariant(int(MScore::OFFSET_VAL));
                  else if (value == "user")
                        return QVariant(int(MScore::USER_VAL));
                  }
                  break;
            case T_PLACEMENT: {
                  QString value(e.readElementText());
                  if (value == "above")
                        return QVariant(int(Element::ABOVE));
                  else if (value == "below")
                        return QVariant(int(Element::BELOW));
                  }
                  break;
            case T_BEAM_MODE:             // TODO
                  return QVariant(int(0));

            case T_GROUPS:
                  {
                  Groups g;
                  g.read(e);
                  return QVariant::fromValue(g);
                  }
            case T_POINT_MM:
            case T_SIZE_MM:
                  return QVariant();
            }
      return QVariant();
      }