Compare commits

...

8 Commits

Author SHA1 Message Date
Laurent Trinques
3cadedaf9e
Merge pull request #401 from Evilscrack/master
Minor corrections to prevent crashes
2025-08-31 11:47:41 +02:00
Pascal Sander
84ac394d3b Refactor to more QRectF to be more compatible with QPrinter. #5 2025-08-30 12:08:54 +02:00
Pascal Sander
27b21b38aa Fixed incorrect cast from ElementCollectionItem to FileElementCollectionItem #4 2025-08-22 20:12:27 +02:00
Evilscrack
12b33e15a3
Merge branch 'qelectrotech:master' into master 2025-08-22 19:26:25 +02:00
Pascal Sander
ee49086d03 QMenu must set a parent for correct position. #3 2025-08-17 17:48:29 +02:00
Pascal Sander
c31cab34e4 Check QAbstractItemModel for nullptr before access. #2 2025-08-17 10:33:04 +02:00
Evilscrack
a61d70e40e
Merge branch 'qelectrotech:master' into master 2025-08-17 09:56:49 +02:00
Pascal Sander
dad637689d QScopedPointer removes QDrag to early and will still be accessed in another thread. #1 2025-08-13 20:01:22 +02:00
8 changed files with 70 additions and 69 deletions

View File

@ -172,10 +172,12 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data,
const QModelIndex &parent)
{
Q_UNUSED(action)
QStandardItem *qsi = itemFromIndex(
parent.QModelIndex::model()->index(row, column));
if (!qsi)
qsi = itemFromIndex(parent);
const QAbstractItemModel* qaim = parent.QModelIndex::model();
if (! qaim) return false;
QStandardItem* qsi = itemFromIndex(qaim->index(row, column));
if (! qsi) qsi = itemFromIndex(parent);
if (qsi->type() == FileElementCollectionItem::Type)
{

View File

@ -591,37 +591,32 @@ void ElementsCollectionWidget::resetShowThisDir()
*/
void ElementsCollectionWidget::dirProperties()
{
ElementCollectionItem *eci = elementCollectionItemForIndex(
m_index_at_context_menu);
//When the user right-clicks on the collection tree and
//selects the collection property, the collection name,
//file path and number of elements will be added
//to the qInfo log file.
qInfo() <<tr("Le dossier") <<(eci->localName())
<<tr("contient")<<eci->elementsChild().size()
<<tr("éléments") <<"\n"<< "Path:"
<<(static_cast<FileElementCollectionItem*>(eci)->fileSystemPath());
if (eci && eci->isDir()) {
QString txt1 = tr("Le dossier %1 contient").arg(
eci->localName());
QString txt2 = tr("%n élément(s), répartie(s)",
"",
eci->elementsChild().size());
QString txt3 = tr("dans %n dossier(s).",
"" ,
eci->directoriesChild().size());
QString txt4 = tr("Chemin de la collection : %1").arg(
eci->collectionPath());
QString txt5;
ElementCollectionItem* eci =
elementCollectionItemForIndex(m_index_at_context_menu);
if (eci && eci->isDir())
{
QString filePath;
if (eci->type() == FileElementCollectionItem::Type) {
txt5 = tr("Chemin dans le système de fichiers : %1")
.arg(static_cast<FileElementCollectionItem*>(eci)->fileSystemPath());
filePath = tr("Chemin dans le système de fichiers : %1")
.arg(
static_cast<FileElementCollectionItem*>(eci)
->fileSystemPath());
}
QString out =
tr("Le dossier %1 contient").arg(eci->localName()) % " "
% tr("%n élément(s), répartie(s)", "", eci->elementsChild().size())
% " "
% tr("dans %n dossier(s).", "", eci->directoriesChild().size())
% "\n\n"
% tr("Chemin de la collection : %1").arg(eci->collectionPath())
% "\n" % filePath;
qInfo() << out;
QMessageBox::information(
this,
tr("Propriété du dossier %1").arg(eci->localName()),
txt1 % " " % txt2 % " " % txt3 % "\n\n" % txt4 % "\n" % txt5);
}
out);
}
}
/**

View File

@ -82,7 +82,11 @@ void ElementsTreeView::startElementDrag(const ElementsLocation &location)
{
if (! location.exist()) return;
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
QDrag* drag = new QDrag(this);
#else
QScopedPointer<QDrag> drag(new QDrag(this));
#endif
QString location_str = location.toString();
QMimeData *mime_data = new QMimeData();

View File

@ -234,9 +234,9 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
{
////Prepare the print////
//Deselect all
// Deselect all
diagram->deselectAll();
//Disable focus flags
// Disable focus flags
QList<QGraphicsItem *> focusable_items;
for (auto qgi : diagram->items()) {
if (qgi->flags() & QGraphicsItem::ItemIsFocusable) {
@ -244,7 +244,7 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
qgi->setFlag(QGraphicsItem::ItemIsFocusable, false);
}
}
//Disable interaction
// Disable interaction
for (auto view : diagram->views()) {
view->setInteractive(false);
}
@ -254,7 +254,7 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
auto full_page = printer->fullPage();
auto diagram_rect = diagramRect(diagram, option);
auto diagram_rect = QRectF(diagramRect(diagram, option));
if (fit_page) {
diagram->render(painter, QRectF(), diagram_rect, Qt::KeepAspectRatio);
} else {
@ -266,57 +266,58 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
#pragma message("@TODO remove code for QT 6 or later")
#endif
qDebug()<<"Help code for QT 6 or later";
auto printed_rect = full_page ? printer->paperRect(QPrinter::Millimeter) : printer->pageRect(QPrinter::Millimeter);
auto printed_rect = full_page ? printer->paperRect(QPrinter::Millimeter) :
printer->pageRect(QPrinter::Millimeter);
#endif
auto used_width = printed_rect.width();
auto used_height = printed_rect.height();
auto h_pages_count = horizontalPagesCount(diagram, option, full_page);
auto v_pages_count = verticalPagesCount(diagram, option, full_page);
QVector<QVector<QRect>> page_grid;
//The diagram is printed on a matrix of sheet
//scrolls through the rows of the matrix
QVector<QVector<QRectF>> page_grid;
// The diagram is printed on a matrix of sheet
// scrolls through the rows of the matrix
auto y_offset = 0;
for (auto i=0 ; i<v_pages_count ; ++i)
for (auto i = 0; i < v_pages_count; ++i)
{
page_grid << QVector<QRect>();
//scrolls through the lines of sheet
page_grid << QVector<QRectF>();
// scrolls through the lines of sheet
auto x_offset = 0;
for (auto j=0 ; j<h_pages_count ; ++j)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
page_grid.last() << QRect(QPoint(x_offset, y_offset),
QSize(qMin(used_width, diagram_rect.width() - x_offset),
qMin(used_height, diagram_rect.height() - y_offset)));
#else
#if TODO_LIST
#pragma message("@TODO remove code for QT 6 or later")
#endif
qDebug()<<"Help code for QT 6 or later";
#endif
page_grid.last() << QRectF(
QPoint(x_offset, y_offset),
QSize(
qMin(used_width, diagram_rect.width() - x_offset),
qMin(used_height, diagram_rect.height() - y_offset)));
x_offset += used_width;
}
y_offset += used_height;
}
//Retains only the pages to be printed
QVector<QRect> page_to_print;
// Retains only the pages to be printed
QVector<QRectF> page_to_print;
for (auto i=0 ; i < v_pages_count ; ++i) {
for (int j=0 ; j < h_pages_count ; ++j) {
page_to_print << page_grid.at(i).at(j);
}
}
//Scrolls through the page for print
// Scrolls through the page for print
bool first_ = true;
for (auto page : page_to_print)
for (auto& page : page_to_print)
{
first_ ? first_ = false : m_printer->newPage();
diagram->render(painter, QRect(QPoint(0,0), page.size()), page.translated(diagram_rect.topLeft()), Qt::KeepAspectRatio);
diagram->render(
painter,
QRectF(QPoint(0, 0), page.size()),
page.translated(diagram_rect.topLeft()),
Qt::KeepAspectRatio);
}
}
////Print is finished, restore diagram and graphics item properties
////Print is finished, restore diagram and graphics item properties
for (auto view : diagram->views()) {
view->setInteractive(true);
}

View File

@ -775,12 +775,12 @@ void QETDiagramEditor::setUpToolBar()
void QETDiagramEditor::setUpMenu()
{
QMenu *menu_fichier = new QMenu(tr("&Fichier"));
QMenu *menu_edition = new QMenu(tr("&Édition"));
QMenu *menu_project = new QMenu(tr("&Projet"));
QMenu *menu_affichage = new QMenu(tr("Afficha&ge"));
//QMenu *menu_outils = new QMenu(tr("O&utils"));
windows_menu = new QMenu(tr("Fe&nêtres"));
QMenu* menu_fichier = new QMenu(tr("&Fichier"), this);
QMenu* menu_edition = new QMenu(tr("&Édition"), this);
QMenu* menu_project = new QMenu(tr("&Projet"), this);
QMenu* menu_affichage = new QMenu(tr("Afficha&ge"), this);
// QMenu *menu_outils = new QMenu(tr("O&utils"), this);
windows_menu = new QMenu(tr("Fe&nêtres"), this);
insertMenu(settings_menu_, menu_fichier);
insertMenu(settings_menu_, menu_edition);

View File

@ -142,13 +142,12 @@ void QETMainWindow::initCommonActions()
*/
void QETMainWindow::initCommonMenus()
{
settings_menu_ = new QMenu(tr("&Configuration", "window menu"));
settings_menu_ = new QMenu(tr("&Configuration", "window menu"), this);
settings_menu_ -> addAction(fullscreen_action_);
settings_menu_ -> addAction(configure_action_);
connect(settings_menu_, SIGNAL(aboutToShow()), this, SLOT(checkToolbarsmenu()));
help_menu_ = new QMenu(tr("&Aide", "window menu"));
help_menu_ = new QMenu(tr("&Aide", "window menu"), this);
help_menu_ -> addAction(whatsthis_action_);
help_menu_ -> addSeparator();
help_menu_ -> addAction(manual_online_);

View File

@ -437,8 +437,8 @@ void QETTitleBlockTemplateEditor::initActions()
*/
void QETTitleBlockTemplateEditor::initMenus()
{
file_menu_ = new QMenu(tr("&Fichier", "menu title"), this);
edit_menu_ = new QMenu(tr("&Édition", "menu title"), this);
file_menu_ = new QMenu(tr("&Fichier", "menu title"), this);
edit_menu_ = new QMenu(tr("&Édition", "menu title"), this);
display_menu_ = new QMenu(tr("Afficha&ge", "menu title"), this);
file_menu_ -> addAction(new_);

View File

@ -338,7 +338,7 @@ void TitleBlockPropertiesWidget::initDialog(
this,
SLOT(duplicateCurrentTitleBlockTemplate()));
m_tbt_menu = new QMenu(tr("Title block templates actions"));
m_tbt_menu = new QMenu(tr("Title block templates actions"), ui->m_tbt_pb);
m_tbt_menu -> addAction(m_tbt_edit);
m_tbt_menu -> addAction(m_tbt_duplicate);
ui -> m_tbt_pb -> setMenu(m_tbt_menu);