mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Totest QRegularExpression ok?
This commit is contained in:
parent
c1e93fc442
commit
ad0df66ab1
@ -56,7 +56,7 @@ TitleBlockCell *TitleBlockTemplate::createCell(
|
|||||||
const TitleBlockCell *existing_cell) {
|
const TitleBlockCell *existing_cell) {
|
||||||
TitleBlockCell *new_cell =
|
TitleBlockCell *new_cell =
|
||||||
existing_cell ? new TitleBlockCell(*existing_cell)
|
existing_cell ? new TitleBlockCell(*existing_cell)
|
||||||
: new TitleBlockCell();
|
: new TitleBlockCell();
|
||||||
registered_cells_ << new_cell;
|
registered_cells_ << new_cell;
|
||||||
return(new_cell);
|
return(new_cell);
|
||||||
}
|
}
|
||||||
@ -260,8 +260,8 @@ TitleBlockTemplate *TitleBlockTemplate::clone() const
|
|||||||
*/
|
*/
|
||||||
void TitleBlockTemplate::loadInformation(const QDomElement &xml_element) {
|
void TitleBlockTemplate::loadInformation(const QDomElement &xml_element) {
|
||||||
for (QDomNode n = xml_element.firstChild() ;
|
for (QDomNode n = xml_element.firstChild() ;
|
||||||
!n.isNull() ;
|
!n.isNull() ;
|
||||||
n = n.nextSibling()) {
|
n = n.nextSibling()) {
|
||||||
if (n.isElement() && n.toElement().tagName() == "information") {
|
if (n.isElement() && n.toElement().tagName() == "information") {
|
||||||
setInformation(n.toElement().text());
|
setInformation(n.toElement().text());
|
||||||
}
|
}
|
||||||
@ -291,12 +291,12 @@ bool TitleBlockTemplate::loadLogos(const QDomElement &xml_element, bool reset) {
|
|||||||
|
|
||||||
// we look for //logos/logo elements
|
// we look for //logos/logo elements
|
||||||
for (QDomNode n = xml_element.firstChild() ;
|
for (QDomNode n = xml_element.firstChild() ;
|
||||||
!n.isNull() ;
|
!n.isNull() ;
|
||||||
n = n.nextSibling()) {
|
n = n.nextSibling()) {
|
||||||
if (n.isElement() && n.toElement().tagName() == "logos") {
|
if (n.isElement() && n.toElement().tagName() == "logos") {
|
||||||
for (QDomNode p = n.firstChild() ;
|
for (QDomNode p = n.firstChild() ;
|
||||||
!p.isNull() ;
|
!p.isNull() ;
|
||||||
p = p.nextSibling()) {
|
p = p.nextSibling()) {
|
||||||
if (p.isElement() && p.toElement().tagName()
|
if (p.isElement() && p.toElement().tagName()
|
||||||
== "logo") {
|
== "logo") {
|
||||||
loadLogo(p.toElement());
|
loadLogo(p.toElement());
|
||||||
@ -357,8 +357,8 @@ bool TitleBlockTemplate::loadGrid(const QDomElement &xml_element) {
|
|||||||
// we parse the first available "grid" XML element
|
// we parse the first available "grid" XML element
|
||||||
QDomElement grid_element;
|
QDomElement grid_element;
|
||||||
for (QDomNode n = xml_element.firstChild() ;
|
for (QDomNode n = xml_element.firstChild() ;
|
||||||
!n.isNull() ;
|
!n.isNull() ;
|
||||||
n = n.nextSibling()) {
|
n = n.nextSibling()) {
|
||||||
if (n.isElement() && n.toElement().tagName() == "grid") {
|
if (n.isElement() && n.toElement().tagName() == "grid") {
|
||||||
grid_element = n.toElement();
|
grid_element = n.toElement();
|
||||||
break;
|
break;
|
||||||
@ -430,10 +430,10 @@ void TitleBlockTemplate::parseColumns(const QString &cols_string) {
|
|||||||
QRegularExpression abs_col_size_format,rel_col_size_format;
|
QRegularExpression abs_col_size_format,rel_col_size_format;
|
||||||
abs_col_size_format.setPattern("^([0-9]+)(?:px)?$");
|
abs_col_size_format.setPattern("^([0-9]+)(?:px)?$");
|
||||||
abs_col_size_format.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
abs_col_size_format.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
//QRegExp rel_col_size_format("^([rt])([0-9]+)%$", Qt::CaseInsensitive);
|
|
||||||
rel_col_size_format.setPattern("^([rt])([0-9]+)%$");
|
rel_col_size_format.setPattern("^([rt])([0-9]+)%$");
|
||||||
rel_col_size_format.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
rel_col_size_format.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
|
qDebug() <<"is QRegularExpression ok?";
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
|
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
|
||||||
QStringList cols_descriptions =
|
QStringList cols_descriptions =
|
||||||
@ -471,7 +471,7 @@ void TitleBlockTemplate::parseColumns(const QString &cols_string) {
|
|||||||
foreach (TitleBlockColDimension icd, columns_width_) {
|
foreach (TitleBlockColDimension icd, columns_width_) {
|
||||||
qDebug() << Q_FUNC_INFO
|
qDebug() << Q_FUNC_INFO
|
||||||
<< QString("%1 [%2]").arg(icd.value).arg(
|
<< QString("%1 [%2]").arg(icd.value).arg(
|
||||||
QET::titleBlockColumnLengthToString(icd.type));
|
QET::titleBlockColumnLengthToString(icd.type));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -487,8 +487,8 @@ bool TitleBlockTemplate::loadCells(const QDomElement &xml_element) {
|
|||||||
// we are interested by the "logo" and "field" elements
|
// we are interested by the "logo" and "field" elements
|
||||||
QDomElement grid_element;
|
QDomElement grid_element;
|
||||||
for (QDomNode n = xml_element.firstChild() ;
|
for (QDomNode n = xml_element.firstChild() ;
|
||||||
!n.isNull() ;
|
!n.isNull() ;
|
||||||
n = n.nextSibling()) {
|
n = n.nextSibling()) {
|
||||||
if (!n.isElement()) continue;
|
if (!n.isElement()) continue;
|
||||||
QDomElement cell_element = n.toElement();
|
QDomElement cell_element = n.toElement();
|
||||||
if (cell_element.tagName() == "field"
|
if (cell_element.tagName() == "field"
|
||||||
@ -648,9 +648,9 @@ void TitleBlockTemplate::saveCell(TitleBlockCell *cell,
|
|||||||
cell_elmt.setAttribute("row", cell -> num_row);
|
cell_elmt.setAttribute("row", cell -> num_row);
|
||||||
cell_elmt.setAttribute("col", cell -> num_col);
|
cell_elmt.setAttribute("col", cell -> num_col);
|
||||||
if (cell -> row_span) cell_elmt.setAttribute("rowspan",
|
if (cell -> row_span) cell_elmt.setAttribute("rowspan",
|
||||||
cell -> row_span);
|
cell -> row_span);
|
||||||
if (cell -> col_span) cell_elmt.setAttribute("colspan",
|
if (cell -> col_span) cell_elmt.setAttribute("colspan",
|
||||||
cell -> col_span);
|
cell -> col_span);
|
||||||
|
|
||||||
// save other information
|
// save other information
|
||||||
cell -> saveContentToXml(cell_elmt);
|
cell -> saveContentToXml(cell_elmt);
|
||||||
@ -1134,8 +1134,8 @@ void TitleBlockTemplate::addColumn(int i) {
|
|||||||
@return true
|
@return true
|
||||||
*/
|
*/
|
||||||
bool TitleBlockTemplate::insertColumn(const TitleBlockDimension &dimension,
|
bool TitleBlockTemplate::insertColumn(const TitleBlockDimension &dimension,
|
||||||
const QList<TitleBlockCell *> &column,
|
const QList<TitleBlockCell *> &column,
|
||||||
int i) {
|
int i) {
|
||||||
int index = (i == -1) ? columns_width_.count() : i;
|
int index = (i == -1) ? columns_width_.count() : i;
|
||||||
cells_.insert(index, column);
|
cells_.insert(index, column);
|
||||||
columns_width_.insert(index, dimension);
|
columns_width_.insert(index, dimension);
|
||||||
@ -1213,11 +1213,11 @@ QSet<TitleBlockCell *> TitleBlockTemplate::spannedCells(
|
|||||||
if (!final_row_span && !final_col_span) return(set);
|
if (!final_row_span && !final_col_span) return(set);
|
||||||
|
|
||||||
for (int i = given_cell -> num_col ;
|
for (int i = given_cell -> num_col ;
|
||||||
i <= given_cell -> num_col + final_col_span ;
|
i <= given_cell -> num_col + final_col_span ;
|
||||||
++ i) {
|
++ i) {
|
||||||
for (int j = given_cell -> num_row ;
|
for (int j = given_cell -> num_row ;
|
||||||
j <= given_cell -> num_row + final_row_span ;
|
j <= given_cell -> num_row + final_row_span ;
|
||||||
++ j) {
|
++ j) {
|
||||||
if (i == given_cell -> num_col && j
|
if (i == given_cell -> num_col && j
|
||||||
== given_cell -> num_row)
|
== given_cell -> num_row)
|
||||||
continue;
|
continue;
|
||||||
@ -1257,7 +1257,7 @@ QHash<TitleBlockCell *, QPair<int, int> > TitleBlockTemplate::getAllSpans(
|
|||||||
@param spans :
|
@param spans :
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplate::setAllSpans(const QHash<TitleBlockCell *,
|
void TitleBlockTemplate::setAllSpans(const QHash<TitleBlockCell *,
|
||||||
QPair<int, int> > &spans) {
|
QPair<int, int> > &spans) {
|
||||||
foreach (TitleBlockCell *cell, spans.keys()) {
|
foreach (TitleBlockCell *cell, spans.keys()) {
|
||||||
cell -> row_span = spans[cell].first;
|
cell -> row_span = spans[cell].first;
|
||||||
cell -> col_span = spans[cell].second;
|
cell -> col_span = spans[cell].second;
|
||||||
@ -1344,9 +1344,9 @@ bool TitleBlockTemplate::addLogoFromFile(const QString &filepath,
|
|||||||
|
|
||||||
// we then try to add it as a bitmap image
|
// we then try to add it as a bitmap image
|
||||||
return addLogo(filename,
|
return addLogo(filename,
|
||||||
&file_content,
|
&file_content,
|
||||||
filepath_info.suffix(),
|
filepath_info.suffix(),
|
||||||
"base64");
|
"base64");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1405,7 +1405,7 @@ bool TitleBlockTemplate::removeLogo(const QString &logo_name) {
|
|||||||
@return
|
@return
|
||||||
*/
|
*/
|
||||||
bool TitleBlockTemplate::renameLogo(const QString &logo_name,
|
bool TitleBlockTemplate::renameLogo(const QString &logo_name,
|
||||||
const QString &new_name) {
|
const QString &new_name) {
|
||||||
if (!data_logos_.contains(logo_name)
|
if (!data_logos_.contains(logo_name)
|
||||||
|| data_logos_.contains(new_name)) {
|
|| data_logos_.contains(new_name)) {
|
||||||
return(false);
|
return(false);
|
||||||
@ -1531,8 +1531,8 @@ void TitleBlockTemplate::render(QPainter &painter,
|
|||||||
// calculate the border rect of the current cell
|
// calculate the border rect of the current cell
|
||||||
int x = lengthRange(0, cells_[i][j] -> num_col, widths);
|
int x = lengthRange(0, cells_[i][j] -> num_col, widths);
|
||||||
int y = lengthRange(0,
|
int y = lengthRange(0,
|
||||||
cells_[i][j] -> num_row,
|
cells_[i][j] -> num_row,
|
||||||
rows_heights_);
|
rows_heights_);
|
||||||
|
|
||||||
int row_span = 0, col_span = 0;
|
int row_span = 0, col_span = 0;
|
||||||
if (cells_[i][j] -> span_state
|
if (cells_[i][j] -> span_state
|
||||||
@ -1541,11 +1541,11 @@ void TitleBlockTemplate::render(QPainter &painter,
|
|||||||
col_span = cells_[i][j] -> applied_col_span;
|
col_span = cells_[i][j] -> applied_col_span;
|
||||||
}
|
}
|
||||||
int w = lengthRange(cells_[i][j] -> num_col,
|
int w = lengthRange(cells_[i][j] -> num_col,
|
||||||
cells_[i][j] -> num_col + 1 + col_span,
|
cells_[i][j] -> num_col + 1 + col_span,
|
||||||
widths);
|
widths);
|
||||||
int h = lengthRange(cells_[i][j] -> num_row,
|
int h = lengthRange(cells_[i][j] -> num_row,
|
||||||
cells_[i][j] -> num_row + 1 + row_span,
|
cells_[i][j] -> num_row + 1 + row_span,
|
||||||
rows_heights_);
|
rows_heights_);
|
||||||
QRect cell_rect(x, y, w, h);
|
QRect cell_rect(x, y, w, h);
|
||||||
|
|
||||||
renderCell(painter, *cells_[i][j],
|
renderCell(painter, *cells_[i][j],
|
||||||
@ -1576,7 +1576,7 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
|
|||||||
QList<int> widths = columnsWidth(titleblock_width);
|
QList<int> widths = columnsWidth(titleblock_width);
|
||||||
|
|
||||||
// draw the titleblock border
|
// draw the titleblock border
|
||||||
double xCoord = title_block_rect.topLeft().x()*Createdxf::xScale;
|
double xCoord = title_block_rect.topLeft().x()*Createdxf::xScale;
|
||||||
double yCoord =
|
double yCoord =
|
||||||
Createdxf::sheetHeight
|
Createdxf::sheetHeight
|
||||||
- title_block_rect.bottomLeft().y()
|
- title_block_rect.bottomLeft().y()
|
||||||
@ -1600,9 +1600,9 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
|
|||||||
|
|
||||||
// calculate the border rect of the current cell
|
// calculate the border rect of the current cell
|
||||||
double x = lengthRange(0, cells_[i][j] -> num_col,
|
double x = lengthRange(0, cells_[i][j] -> num_col,
|
||||||
widths);
|
widths);
|
||||||
double y = lengthRange(0, cells_[i][j] -> num_row,
|
double y = lengthRange(0, cells_[i][j] -> num_row,
|
||||||
rows_heights_);
|
rows_heights_);
|
||||||
|
|
||||||
int row_span = 0, col_span = 0;
|
int row_span = 0, col_span = 0;
|
||||||
if (cells_[i][j] -> span_state
|
if (cells_[i][j] -> span_state
|
||||||
@ -1611,11 +1611,11 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
|
|||||||
col_span = cells_[i][j] -> applied_col_span;
|
col_span = cells_[i][j] -> applied_col_span;
|
||||||
}
|
}
|
||||||
double w = lengthRange(cells_[i][j] -> num_col,
|
double w = lengthRange(cells_[i][j] -> num_col,
|
||||||
cells_[i][j] -> num_col + 1 + col_span,
|
cells_[i][j] -> num_col + 1 + col_span,
|
||||||
widths);
|
widths);
|
||||||
double h = lengthRange(cells_[i][j] -> num_row,
|
double h = lengthRange(cells_[i][j] -> num_row,
|
||||||
cells_[i][j] -> num_row + 1 + row_span,
|
cells_[i][j] -> num_row + 1 + row_span,
|
||||||
rows_heights_);
|
rows_heights_);
|
||||||
|
|
||||||
x = xCoord + x*Createdxf::xScale;
|
x = xCoord + x*Createdxf::xScale;
|
||||||
h *= Createdxf::yScale;
|
h *= Createdxf::yScale;
|
||||||
@ -1655,9 +1655,9 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
|
|||||||
Rectangle the cell must be rendered into.
|
Rectangle the cell must be rendered into.
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplate::renderCell(QPainter &painter,
|
void TitleBlockTemplate::renderCell(QPainter &painter,
|
||||||
const TitleBlockCell &cell,
|
const TitleBlockCell &cell,
|
||||||
const DiagramContext &diagram_context,
|
const DiagramContext &diagram_context,
|
||||||
const QRect &cell_rect) const
|
const QRect &cell_rect) const
|
||||||
{
|
{
|
||||||
// draw the border rect of the current cell
|
// draw the border rect of the current cell
|
||||||
QPen pen(QBrush(), 0.0, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
QPen pen(QBrush(), 0.0, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
||||||
@ -1819,7 +1819,7 @@ void TitleBlockTemplate::renderTextCell(QPainter &painter,
|
|||||||
QRectF new_world_cell_rect(cell_rect);
|
QRectF new_world_cell_rect(cell_rect);
|
||||||
new_world_cell_rect.moveTo(0, 0.0);
|
new_world_cell_rect.moveTo(0, 0.0);
|
||||||
new_world_cell_rect.setWidth(new_world_cell_rect.width()
|
new_world_cell_rect.setWidth(new_world_cell_rect.width()
|
||||||
/ ratio);
|
/ ratio);
|
||||||
painter.drawText(new_world_cell_rect,
|
painter.drawText(new_world_cell_rect,
|
||||||
cell.alignment,
|
cell.alignment,
|
||||||
text);
|
text);
|
||||||
@ -2014,11 +2014,11 @@ bool TitleBlockTemplate::checkCellSpan(TitleBlockCell *cell) {
|
|||||||
|
|
||||||
// ensure cells that will be spanned are either empty or free
|
// ensure cells that will be spanned are either empty or free
|
||||||
for (int i = cell -> num_col ;
|
for (int i = cell -> num_col ;
|
||||||
i <= cell -> num_col + cell -> applied_col_span ;
|
i <= cell -> num_col + cell -> applied_col_span ;
|
||||||
++ i) {
|
++ i) {
|
||||||
for (int j = cell -> num_row ;
|
for (int j = cell -> num_row ;
|
||||||
j <= cell -> num_row + cell -> applied_row_span ;
|
j <= cell -> num_row + cell -> applied_row_span ;
|
||||||
++ j) {
|
++ j) {
|
||||||
if (i == cell -> num_col && j == cell -> num_row)
|
if (i == cell -> num_col && j == cell -> num_row)
|
||||||
continue;
|
continue;
|
||||||
#ifdef TITLEBLOCK_TEMPLATE_DEBUG
|
#ifdef TITLEBLOCK_TEMPLATE_DEBUG
|
||||||
@ -2031,8 +2031,8 @@ bool TitleBlockTemplate::checkCellSpan(TitleBlockCell *cell) {
|
|||||||
current_cell -> spanner_cell
|
current_cell -> spanner_cell
|
||||||
&& current_cell -> spanner_cell
|
&& current_cell -> spanner_cell
|
||||||
!= cell
|
!= cell
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
cell -> span_state = TitleBlockCell::Disabled;
|
cell -> span_state = TitleBlockCell::Disabled;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -2058,11 +2058,11 @@ void TitleBlockTemplate::applyCellSpan(TitleBlockCell *cell)
|
|||||||
|
|
||||||
// goes through every spanned cell
|
// goes through every spanned cell
|
||||||
for (int i = cell -> num_col ;
|
for (int i = cell -> num_col ;
|
||||||
i <= cell -> num_col + cell -> applied_col_span ;
|
i <= cell -> num_col + cell -> applied_col_span ;
|
||||||
++ i) {
|
++ i) {
|
||||||
for (int j = cell -> num_row ;
|
for (int j = cell -> num_row ;
|
||||||
j <= cell -> num_row + cell -> applied_row_span ;
|
j <= cell -> num_row + cell -> applied_row_span ;
|
||||||
++ j) {
|
++ j) {
|
||||||
// avoid the spanning cell itself
|
// avoid the spanning cell itself
|
||||||
if (i == cell -> num_col && j == cell -> num_row)
|
if (i == cell -> num_col && j == cell -> num_row)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user