本文整理汇总了C++中QStringRef::toDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::toDouble方法的具体用法?C++ QStringRef::toDouble怎么用?C++ QStringRef::toDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::toDouble方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FromCapture
Tag Tag::FromCapture(const QRegularExpressionMatch &match, const QStringList &groups)
{
QMap<QString, QString> data = multiMatchToMap(match, groups);
// Tag
QString tag;
if (data.contains("tag"))
{
tag = data["tag"].replace(" ", "_").replace("&", "&").trimmed();
}
// Type
QString type;
if (data.contains("type"))
{
static QStringList types = QStringList() << "general" << "artist" << "unknown" << "copyright" << "character" << "species" << "meta";
type = Tag::GetType(data.value("type").trimmed(), stringListToMap(types));
}
if (type.isEmpty())
{ type = "unknown"; }
// Count
int count = 0;
if (data.contains("count"))
{
QString countStr = data.value("count").toLower().trimmed();
countStr.remove(',');
if (countStr.endsWith('k'))
{
QStringRef withoutK = countStr.leftRef(countStr.length() - 1).trimmed();
count = qRound(withoutK.toDouble() * 1000);
}
else
{ count = countStr.toInt(); }
}
return Tag(tag, type, count);
}
示例2: loadMOJ
bool Document::loadMOJ(QString fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
return false;
}
QXmlStreamReader reader;
// check if it is a gzipped moj
QByteArray s = file.read(2);
if (s.size() == 2)
{
if (s.at(0) == static_cast<char>(0x1f) && s.at(1) == static_cast<char>(0x8b))
{
// this is a gzipped file
file.reset();
QByteArray compressedData = file.readAll();
QByteArray uncompressedData;
if (!QCompressor::gzipDecompress(compressedData, uncompressedData))
{
return false;
}
reader.addData(uncompressedData);
}
else
{
file.reset();
reader.setDevice(&file);
}
}
else
{
return false;
}
pages.clear();
int strokeCount = 0;
while (!reader.atEnd())
{
reader.readNext();
if (reader.name() == "MrWriter" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef docversion = attributes.value("document-version");
if (docversion.toInt() > DOC_VERSION)
{
// TODO warn about newer document version
}
}
if (reader.name() == "page" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef width = attributes.value("", "width");
QStringRef height = attributes.value("", "height");
Page newPage;
newPage.setWidth(width.toDouble());
newPage.setHeight(height.toDouble());
pages.append(newPage);
}
if (reader.name() == "background" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef color = attributes.value("", "color");
QColor newColor = stringToColor(color.toString());
pages.last().setBackgroundColor(newColor);
}
if (reader.name() == "stroke" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef tool = attributes.value("", "tool");
if (tool == "pen")
{
Stroke newStroke;
newStroke.pattern = MrDoc::solidLinePattern;
QStringRef color = attributes.value("", "color");
newStroke.color = stringToColor(color.toString());
QStringRef style = attributes.value("", "style");
if (style.toString().compare("solid") == 0)
{
newStroke.pattern = MrDoc::solidLinePattern;
}
else if (style.toString().compare("dash") == 0)
{
newStroke.pattern = MrDoc::dashLinePattern;
}
else if (style.toString().compare("dashdot") == 0)
{
newStroke.pattern = MrDoc::dashDotLinePattern;
}
else if (style.toString().compare("dot") == 0)
{
newStroke.pattern = MrDoc::dotLinePattern;
}
else
{
//.........这里部分代码省略.........
示例3: loadXOJ
bool Document::loadXOJ(QString fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
return false;
}
QXmlStreamReader reader;
// check if it is a gzipped xoj
QByteArray s = file.read(2);
if (s.size() == 2)
{
if (s.at(0) == static_cast<char>(0x1f) && s.at(1) == static_cast<char>(0x8b))
{
// this is a gzipped file
file.reset();
QByteArray compressedData = file.readAll();
QByteArray uncompressedData;
if (!QCompressor::gzipDecompress(compressedData, uncompressedData))
{
return false;
}
reader.addData(uncompressedData);
}
else
{
file.reset();
reader.setDevice(&file);
}
}
else
{
return false;
}
pages.clear();
int strokeCount = 0;
while (!reader.atEnd())
{
reader.readNext();
if (reader.name() == "page" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef width = attributes.value("", "width");
QStringRef height = attributes.value("", "height");
Page newPage;
newPage.setWidth(width.toDouble());
newPage.setHeight(height.toDouble());
pages.append(newPage);
}
if (reader.name() == "background" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef color = attributes.value("", "color");
QColor newColor = stringToColor(color.toString());
pages.last().setBackgroundColor(newColor);
}
if (reader.name() == "stroke" && reader.tokenType() == QXmlStreamReader::StartElement)
{
QXmlStreamAttributes attributes = reader.attributes();
QStringRef tool = attributes.value("", "tool");
if (tool == "pen")
{
Stroke newStroke;
newStroke.pattern = MrDoc::solidLinePattern;
QStringRef color = attributes.value("", "color");
newStroke.color = stringToColor(color.toString());
QStringRef strokeWidth = attributes.value("", "width");
QStringList strokeWidthList = strokeWidth.toString().split(" ");
newStroke.penWidth = strokeWidthList.at(0).toDouble();
newStroke.pressures.append(newStroke.penWidth / strokeWidthList.at(0).toDouble());
for (int i = 1; i < strokeWidthList.size(); ++i)
{
newStroke.pressures.append(2 * strokeWidthList.at(i).toDouble() / newStroke.penWidth - newStroke.pressures.at(i - 1));
}
QString elementText = reader.readElementText();
QStringList elementTextList = elementText.split(" ");
for (int i = 0; i + 1 < elementTextList.size(); i = i + 2)
{
newStroke.points.append(QPointF(elementTextList.at(i).toDouble(), elementTextList.at(i + 1).toDouble()));
}
while (newStroke.points.size() > newStroke.pressures.size())
{
newStroke.pressures.append(1.0);
}
pages.last().appendStroke(newStroke);
strokeCount++;
qDebug() << strokeCount;
}
}
}
// QFileInfo fileInfo(file);
file.close();
//.........这里部分代码省略.........