mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-06 21:34:13 +02:00
87a010eb75
Fixes https://qelectrotech.org/bugtracker/view.php?id=332 localName() set a non-root folder's label only inside the success path of loading its qet_directory file. If that load failed -- file missing, malformed, or unopenable because of the Windows path-encoding problem with accented characters that plc-user diagnosed on the tracker -- nothing was set at all, and since a fresh item's text() is null the folder rendered with a completely blank label. That is the reported symptom. Resolve the name into a local and always fall back to the folder's own directory name, so the label is never empty whatever went wrong. The fallback is applied *after* NamesList::name() rather than passed into it. This matters: name() returns a caller-supplied fallback before it reaches its "first available translation" step, so passing m_path in would replace a perfectly good name in some other language with the raw directory name. A folder named only in French, viewed under an English locale, previously showed "Accentué" and must keep doing so. Falling back on its own would then hide the broken file -- the user sees a plausible name and never learns there is anything to repair. So a folder whose qet_directory could not be read now says so in its tooltip, naming the file, above the collection path that tooltip already carried. Suggested by plc-user on PR #622. The flag is recorded in localName() and consumed in setUpData(), because setUpData() assigns the tooltip after localName() runs and would otherwise discard it. Only a file-level failure is flagged. A readable qet-directory with no entry for the current language is not an error; NamesList::name() resolves that itself and no warning is shown. Verified on a fixture collection of four folders -- valid, malformed, missing, and one named only in French: master this patch fr-only Accentué Accentué (no warning) malformed <blank> malformed (warning) no qet_directory <blank> no_file (warning) valid Valid Folder Valid Folder (no warning)
75 lines
2.4 KiB
C++
75 lines
2.4 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef FILEELEMENTCOLLECTIONITEM2_H
|
|
#define FILEELEMENTCOLLECTIONITEM2_H
|
|
|
|
#include "elementcollectionitem.h"
|
|
#include "elementslocation.h"
|
|
|
|
/**
|
|
@brief The FileElementCollectionItem class
|
|
This class specialise ElementCollectionItem for manage a collection in
|
|
a file system. They represente a directory or an element.
|
|
*/
|
|
class FileElementCollectionItem : public ElementCollectionItem
|
|
{
|
|
public:
|
|
FileElementCollectionItem();
|
|
|
|
enum { Type = UserType+2 };
|
|
int type() const override { return Type;}
|
|
|
|
bool setRootPath(const QString& path,
|
|
bool set_data = true,
|
|
bool hide_element = false);
|
|
QString fileSystemPath() const;
|
|
QString dirPath() const;
|
|
|
|
bool isDir() const override;
|
|
bool isElement() const override;
|
|
QString localName() override;
|
|
QString localName(const ElementsLocation &location);
|
|
QString name() const override;
|
|
QString collectionPath() const override;
|
|
bool isCollectionRoot() const override;
|
|
bool isCommonCollection() const;
|
|
bool isCompanyCollection() const;
|
|
bool isCustomCollection() const;
|
|
bool isMacrosCollection() const;
|
|
void addChildAtPath(const QString &collection_name) override;
|
|
|
|
void setUpData() override;
|
|
void setUpIcon() override;
|
|
|
|
private:
|
|
void setPathName(const QString& path_name,
|
|
bool set_data = true,
|
|
bool hide_element = false);
|
|
void populate(bool set_data = true, bool hide_element = false);
|
|
|
|
private:
|
|
QString m_path;
|
|
/// True when this directory's qet_directory file is missing or
|
|
/// unreadable, so setUpData() can say so in the tooltip. Recorded
|
|
/// rather than acted on in localName(), because setUpData() resets
|
|
/// the tooltip afterwards and would otherwise discard it.
|
|
bool m_qet_directory_unreadable = false;
|
|
};
|
|
|
|
#endif // FILEELEMENTCOLLECTIONITEM2_H
|