Merge pull request #401 from Evilscrack/master

Minor corrections to prevent crashes
This commit is contained in:
Laurent Trinques 2025-08-31 11:47:41 +02:00 committed by GitHub
commit 3cadedaf9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 70 additions and 69 deletions

View File

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

View File

@ -591,37 +591,32 @@ void ElementsCollectionWidget::resetShowThisDir()
*/ */
void ElementsCollectionWidget::dirProperties() void ElementsCollectionWidget::dirProperties()
{ {
ElementCollectionItem *eci = elementCollectionItemForIndex( ElementCollectionItem* eci =
m_index_at_context_menu); elementCollectionItemForIndex(m_index_at_context_menu);
//When the user right-clicks on the collection tree and
//selects the collection property, the collection name, if (eci && eci->isDir())
//file path and number of elements will be added {
//to the qInfo log file. QString filePath;
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;
if (eci->type() == FileElementCollectionItem::Type) { if (eci->type() == FileElementCollectionItem::Type) {
txt5 = tr("Chemin dans le système de fichiers : %1") filePath = tr("Chemin dans le système de fichiers : %1")
.arg(static_cast<FileElementCollectionItem*>(eci)->fileSystemPath()); .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( QMessageBox::information(
this, this,
tr("Propriété du dossier %1").arg(eci->localName()), 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 (! location.exist()) return;
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
QDrag* drag = new QDrag(this);
#else
QScopedPointer<QDrag> drag(new QDrag(this)); QScopedPointer<QDrag> drag(new QDrag(this));
#endif
QString location_str = location.toString(); QString location_str = location.toString();
QMimeData *mime_data = new QMimeData(); QMimeData *mime_data = new QMimeData();

View File

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

View File

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

View File

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

View File

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

View File

@ -338,7 +338,7 @@ void TitleBlockPropertiesWidget::initDialog(
this, this,
SLOT(duplicateCurrentTitleBlockTemplate())); 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_edit);
m_tbt_menu -> addAction(m_tbt_duplicate); m_tbt_menu -> addAction(m_tbt_duplicate);
ui -> m_tbt_pb -> setMenu(m_tbt_menu); ui -> m_tbt_pb -> setMenu(m_tbt_menu);