コード例 #1
0
ファイル: formularmodel.cpp プロジェクト: twister9893/home
bool FormularModel::setData(const QModelIndex &index, const QVariant &value, int role) {
    if(index.isValid() && role == Qt::EditRole) {
        FieldData *field = m_formularData.at(index.row());
        if(field != NULL) {
            switch(field->getType()) {
                case FieldData::Integer:
                case FieldData::Real:
                case FieldData::Boolean:
                case FieldData::String:
                case FieldData::Unused: {
                    delete field;
                    break;
                }
                case FieldData::Scalable: {
                    delete static_cast<FieldScalable*>(field);
                    break;
                }
                case FieldData::Enumeration: {
                    delete static_cast<FieldEnumeration*>(field);
                    break;
                }
                case FieldData::Constant: {
                    delete static_cast<FieldConstant*>(field);
                    break;
                }
            }
        }
        m_formularData.replace(index.row(), (FieldData*)value.toInt());
        emit dataChanged(index, index);
        return true;
    }
    return false;
}
コード例 #2
0
ファイル: formularmodel.cpp プロジェクト: twister9893/home
bool FormularModel::removeRows(int row, int count, const QModelIndex &parent) {
    if (row >= 0) {
        beginRemoveRows(parent, row, row + count - 1);
        for(int i = 0; i < count; i++) {
            FieldData *field = m_formularData.takeAt(row);
            if(field != NULL) {
                switch(field->getType()) {
                    case FieldData::Integer:
                    case FieldData::Real:
                    case FieldData::Boolean:
                    case FieldData::String:
                    case FieldData::Unused: {
                        delete field;
                        break;
                    }
                    case FieldData::Scalable: {
                        delete static_cast<FieldScalable*>(field);
                        break;
                    }
                    case FieldData::Enumeration: {
                        delete static_cast<FieldEnumeration*>(field);
                        break;
                    }
                    case FieldData::Constant: {
                        delete static_cast<FieldConstant*>(field);
                        break;
                    }
                }
            }
        }
        endRemoveRows();
        emit dataChanged(index(row), index(row + count - 1, formularHeaderSections.size() - 1));
        return true;
    }
    return false;
}
コード例 #3
0
ファイル: formularmodel.cpp プロジェクト: twister9893/home
QVariant FormularModel::data(const QModelIndex &index, int role) const {
    QVariant data = QVariant();
    if(index.isValid()) {
        FieldData *field = m_formularData.at(index.row());
        if(field != NULL) {
            switch(role) {
                case Qt::DisplayRole: {
                    HeaderSection section = (HeaderSection)index.column();
                    switch(section) {
                        case Size: {
                            data = QVariant(field->getSize());
                            break;
                        }
                        case Type: {
                            data = QVariant(FieldData::types.at(field->getType()));
                            break;
                        }
                        case Name: {
                            data = QVariant(field->getName());
                            break;
                        }
                        case Description: {
                            data = QVariant(field->getDescription());
                            break;
                        }
                    }
                    break;
                }
                case Qt::EditRole: {
                    data = QVariant((long long int)field);
                    break;
                }
                case Qt::ToolTipRole: {
                    QString toolTip = QString::fromUtf8(    "Размер:\t\t%size\n"
                                                            "Тип:\t\t\t%type\n"
                                                            "Размерность:\t\t%dimension\n"
                                                            "Наименование:\t%name\n"
                                                            "Описание:\t\t%description"
                                                            "%additional"
                                                            );
                    toolTip.replace("%size", QString::number(field->getSize()));
                    toolTip.replace("%type", FieldData::types.at(field->getType()));
                    toolTip.replace("%dimension", FieldData::dimensions.at(field->getDimension()));
                    toolTip.replace("%name", field->getName());
                    toolTip.replace("%description", field->getDescription());
                    switch(field->getType()) {
                        case FieldData::Integer:
                        case FieldData::Real:
                        case FieldData::Boolean:
                        case FieldData::String:
                        case FieldData::Unused: {
                            toolTip.replace("%additional", QString());
                            break;
                        }
                        case FieldData::Scalable: {
                            FieldScalable *fieldScalable = static_cast<FieldScalable*>(field);
                            QString additional = QString::fromUtf8( "\n\nЦена %kind разряда:\t%order\n"
                                                                    "%sign"
                                                                    );
                            if(fieldScalable->hasAdditionalCode()) {
                                additional.replace("%sign", QString::fromUtf8("Знак в дополнительном коде"));
                            } else if(fieldScalable->hasHighBitSign()) {
                                additional.replace("%sign", QString::fromUtf8("Знак в старшем разряде"));
                            } else {
                                additional.replace("%sign", QString());
                            }
                            if(fieldScalable->getHighOrderBit() != 0.0) {
                                additional.replace("%kind", QString::fromUtf8("старшего"));
                                additional.replace("%order", QString::number(fieldScalable->getHighOrderBit()));
                            } else if(fieldScalable->getLowerOrderBit() != 0.0) {
                                additional.replace("%kind", QString::fromUtf8("младшего"));
                                additional.replace("%order", QString::number(fieldScalable->getLowerOrderBit()));
                            } else {
                                additional = QString();
                            }
                            toolTip.replace("%additional", additional);
                            break;
                        }
                        case FieldData::Enumeration: {
                            FieldEnumeration *fieldEnumeration = static_cast<FieldEnumeration*>(field);
                            QString additional = "\n";
                            for(int i = 0; i < fieldEnumeration->getElements().size(); i++) {
                                additional.append("\n%code - %transcript");
                                additional.replace("%code", fieldEnumeration->getElements()[i].getCode());
                                additional.replace("%transcript", fieldEnumeration->getElements()[i].getTranscript());
                            }
                            toolTip.replace("%additional", additional);
                            break;
                        }
                        case FieldData::Constant: {
                            FieldConstant *fieldConstant = static_cast<FieldConstant*>(field);
                            QString additional = QString::fromUtf8("\n\nКонстанта %constant");
                            additional.replace("%constant", fieldConstant->getValue());
                            toolTip.replace("%additional", additional);
                            break;
                        }
                    }
                    data = QVariant(toolTip);
                    break;
                }
//                case Qt::SizeHintRole: {
//                    int size = 0;
//                    for(int i = 0; i <= index.row(); i++) {
//                        size += index.model()->index(i, Size).data(Qt::DisplayRole).toInt();
//                    }
//                    qDebug() << "Size" << size;
//                    if(size == 16) {
//                        data = QVariant(QSize(50,40));
//                    } else {
//                        data = QVariant(QSize(50, 20));
//                    }
//                    break;
//                }
            }
        }
    }
    return data;
}
コード例 #4
0
void TextFileStorage::saveToIndividualFile()
{

	string str;
	ofstream file;

  // Declare actual field data object.
  FieldData* data; 

  // Get the initial position of the internal iterator of the Datahandler.
  int pos = this->getInput()->getPosition();

	ObjectData* objectData = NULL;
	if( onlyCurrent )
	{
		// Get the current data object.
		objectData = getInput()->getCurrentObject();
	}
	else
	{
		// Get the first data object.
		objectData = getInput()->getFirstObjectCompleted();  
	}

	// Loop over all elements in the datahandler
	while( objectData != NULL)
	{

		// Create the file name.
		stringstream integerConvertor;
		integerConvertor << fileNumber++;
		str = this->getLocation() + this->getFileName() + integerConvertor.str();

		// Open the file;
		file.open( str.c_str() );
		
		if( file.is_open() )
		{
			
			// Loop through all fieldData elements in an objectData object.
			for( int j = 0; j < objectData->getSize(); j++ )
			{
				data = objectData->getDataAt(j);
				
				switch( data->getType() )
				{
					case typeFieldDataInt:
						file << data->getInt() << endl;
					break;
					
					case typeFieldDataFloat:
						file << data->getFloat() << endl;
					break;
					
					case typeFieldDataDouble:
						file << data->getDouble() << endl;
					break;
					
					case typeFieldDataString:
						file << data->getString() << endl;
					break;
					
					case typeFieldDataBool:
						if( data->getBool() )
						{
							file << "true" << endl;
						}
						else
						{
							file << "false" << endl;
						}
					break;				
				}		
			}			
			
			file.close();
		}
		else
		{
			//TODO throw
		}		
		
	
		if( onlyCurrent )
		{
			// Stop the loop if only the current object is to be executed.
			objectData = NULL;
		}
		else
		{		
			// Get the next data object.
			objectData = getInput()->getNextObjectCompleted(); 
		} 		
		
		
	}

  // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator.
  (this->getInput())->getObjectAt( pos );


	// Set the output to the location of the files.
	this->setOutput( this->getLocation() );

};
コード例 #5
0
void TextFileStorage::saveToSingleFile()
{

	string str = this->getLocation() + this->getFileName();

	ofstream file( str.c_str(), ios::app);
  
  // Get the initial position of the internal iterator of the Datahandler.
  int pos = this->getInput()->getPosition();
  

  
  if( file.is_open() )
  {
    
  	ObjectData* objectData = NULL;
  	if( onlyCurrent )
  	{
  		// Get the current data object.
  		objectData = getInput()->getCurrentObject();
  	}
  	else
  	{
  		// Get the first data object.
  		objectData = getInput()->getFirstObjectCompleted();  
  	}
    
    // Declare actual field data object.
    FieldData* data; 

		// Loop through all objectData elements in the Datahandler which are finched.
    while( objectData != NULL )
    {

			// Start with a new object.
			file << "\n# BEGIN OF OBJECT\n";
						
			// Loop through all fieldData elements in an objectData object.
			for( int j = 0; j < objectData->getSize(); j++ )
			{
				data = objectData->getDataAt(j);
				

				switch( data->getType() )
				{
					case typeFieldDataInt:
						file << data->getInt() << "\n";
					break;
					
					case typeFieldDataFloat:
						file << data->getFloat() << "\n";
					break;
					
					case typeFieldDataDouble:  
						file << data->getDouble() << "\n";
					break;
					
					case typeFieldDataString:
						file << data->getString() << "\n";
					break;
					
					case typeFieldDataBool:
						if( data->getBool() )
						{
							file << "true\n";
						}
						else
						{
							file << "false\n";
						}
					break;				
				}		
			}
			
			// The end of the object
			file << "# END OF OBJECT\n";
			
			if( onlyCurrent )
			{
				// Stop the loop if only the current object is to be executed.
				objectData = NULL;
			}
			else
			{		
				// Get the next data object.
				objectData = getInput()->getNextObjectCompleted(); 
			} 
			  	
    }
    

	  // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator.
	  getInput()->getObjectAt( pos );
    
    // Close the file.
    file.close();

  }
  else
	{
		//TODO throw
	}


  // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator.
  (this->getInput())->getObjectAt( pos );


	// Set the output to the full file name.
	this->setOutput( this->getLocation() + this->getFileName() );


};
コード例 #6
0
ファイル: formulareditor.cpp プロジェクト: twister9893/home
bool FormularEditor::writeToFile(QString fileName) {
    QDomDocument domDocument("formular");
    QDomNode xmlNode = domDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
    domDocument.insertBefore(xmlNode, domDocument.firstChildElement());
    QDomElement domRoot;
    domRoot = domDocument.createElement("formular");
    domRoot.setAttribute("capacity", Formular::capacities.at(ui->capacityBox->currentIndex()));
    domRoot.setAttribute("description", ui->descriptionEdit->toPlainText());
    domDocument.appendChild(domRoot);
    for(int i = 0; i < m_formularModel->rowCount(); i++) {
        QDomElement domField = domDocument.createElement("field");
        domRoot.appendChild(domField);
        FieldData *field = (FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt();
        domField.setAttribute("name", field->getName());
        domField.setAttribute("description", field->getDescription());
        domField.setAttribute("type", FieldData::types.at(field->getType()));
        domField.setAttribute("dimension", FieldData::dimensions.at(field->getDimension()));
        domField.setAttribute("size", field->getSize());
        switch(field->getType()) {
            case FieldData::Integer:
            case FieldData::Real:
            case FieldData::Boolean:
            case FieldData::String:
            case FieldData::Unused: {
                break;
            }
            case FieldData::Scalable: {
                FieldScalable *fieldScalable = static_cast<FieldScalable*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt());
                domField.setAttribute("highOrderBit", fieldScalable->getHighOrderBit());
                domField.setAttribute("lowerOrderBit", fieldScalable->getLowerOrderBit());
                domField.setAttribute("additionalCode", fieldScalable->hasAdditionalCode());
                domField.setAttribute("highBitSign", fieldScalable->hasHighBitSign());
                break;
            }
            case FieldData::Enumeration: {
                FieldEnumeration *fieldEnumeration = static_cast<FieldEnumeration*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt());
                for (int j = 0; j < fieldEnumeration->getElements().size(); j++) {
                    QDomElement domEnumerationElement = domDocument.createElement("element");
                    domField.appendChild(domEnumerationElement);
                    domEnumerationElement.setAttribute("code", fieldEnumeration->getElements()[j].getCode());
                    domEnumerationElement.setAttribute("acronym", fieldEnumeration->getElements()[j].getAcronym());
                    domEnumerationElement.setAttribute("transcript", fieldEnumeration->getElements()[j].getTranscript());
                }
                break;
            }
            case FieldData::Constant: {
                FieldConstant *fieldConstant = static_cast<FieldConstant*>((FieldData*)m_formularModel->data(m_formularModel->index(i), Qt::EditRole).toInt());
                domField.setAttribute("value", fieldConstant->getValue());
                break;
            }
        }
    }

    QFile file(fileName);
    if(!file.open(QIODevice::WriteOnly))
            return false;
    QTextStream st(&file);
    domDocument.save(st, 4);
    file.close();
    return true;
}