Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] code clean #14177

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Gui/CommandStd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@
eType = 0;
}

void StdCmdWorkbench::activated(int i)

Check warning on line 80 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

parameter name 'i' is too short, expected at least 2 characters [readability-identifier-length]
{
try {
Workbench* w = WorkbenchManager::instance()->active();

Check warning on line 83 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable name 'w' is too short, expected at least 2 characters [readability-identifier-length]
QList<QAction*> items = static_cast<WorkbenchGroup*>(_pcAction)->actions();

Check warning on line 84 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
std::string switch_to = (const char*)items[i]->objectName().toLatin1();
if (w) {
std::string current_w = w->name();
if (switch_to == current_w)

Check warning on line 88 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
return;
}
doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());

Check warning on line 91 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
}
catch(const Base::PyException& e) {
QString msg(QLatin1String(e.what()));
Expand All @@ -96,7 +96,7 @@
QRegularExpression rx;
rx.setPattern(QLatin1String(R"(^\s*<type 'exceptions.\w*'>:\s*)"));
auto match = rx.match(msg);
if (match.hasMatch())

Check warning on line 99 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
msg = msg.mid(match.capturedLength());
QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
}
Expand All @@ -113,12 +113,12 @@

Action * StdCmdWorkbench::createAction()
{
Action *pcAction;

Check warning on line 116 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'pcAction' is not initialized [cppcoreguidelines-init-variables]

pcAction = new WorkbenchGroup(this,getMainWindow());
pcAction->setShortcut(QString::fromLatin1(getAccel()));
applyCommandData(this->className(), pcAction);
if (getPixmap())

Check warning on line 121 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(getPixmap()));

return pcAction;
Expand Down Expand Up @@ -150,7 +150,7 @@
void StdCmdRecentFiles::activated(int iMsg)
{
auto act = qobject_cast<RecentFilesAction*>(_pcAction);
if (act) act->activateFile( iMsg );

Check warning on line 153 in src/Gui/CommandStd.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
}

/**
Expand Down Expand Up @@ -969,7 +969,7 @@
sWhatsThis = "Std_ReloadStyleSheet";
}

void StdCmdReloadStyleSheet::activated(int iMsg)
void StdCmdReloadStyleSheet::activated(int )
{
auto mw = getMainWindow();

Expand Down
1 change: 0 additions & 1 deletion src/Gui/DlgActionsImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#endif

#include "DlgActionsImp.h"
#include "ui_DlgActions.h"

Check failure on line 37 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'ui_DlgActions.h' file not found [clang-diagnostic-error]
#include "Action.h"
#include "Application.h"
#include "BitmapFactory.h"
Expand Down Expand Up @@ -122,17 +122,17 @@
int index = topLevel->metaObject()->indexOfSignal( QMetaObject::normalizedSignature("addMacroAction(const QByteArray&)") );
if ( index >= 0 ) {
if ( e->type() == QEvent::ParentChange ) {
connect(this, SIGNAL(addMacroAction( const QByteArray& )),

Check warning on line 125 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

connect(this, SIGNAL(addMacroAction( const QByteArray& )),
topLevel, SIGNAL(addMacroAction( const QByteArray& )));

Check warning on line 126 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

topLevel, SIGNAL(addMacroAction( const QByteArray& )));
connect(this, SIGNAL(removeMacroAction( const QByteArray& )),

Check warning on line 127 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

connect(this, SIGNAL(removeMacroAction( const QByteArray& )),
topLevel, SIGNAL(removeMacroAction( const QByteArray& )));

Check warning on line 128 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

topLevel, SIGNAL(removeMacroAction( const QByteArray& )));
connect(this, SIGNAL(modifyMacroAction( const QByteArray& )),

Check warning on line 129 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

connect(this, SIGNAL(modifyMacroAction( const QByteArray& )),
topLevel, SIGNAL(modifyMacroAction( const QByteArray& )));

Check warning on line 130 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

topLevel, SIGNAL(modifyMacroAction( const QByteArray& )));
} else {
disconnect(this, SIGNAL(addMacroAction( const QByteArray& )),

Check warning on line 132 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

disconnect(this, SIGNAL(addMacroAction( const QByteArray& )),
topLevel, SIGNAL(addMacroAction( const QByteArray& )));

Check warning on line 133 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

topLevel, SIGNAL(addMacroAction( const QByteArray& )));
disconnect(this, SIGNAL(removeMacroAction( const QByteArray& )),

Check warning on line 134 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

disconnect(this, SIGNAL(removeMacroAction( const QByteArray& )),
topLevel, SIGNAL(removeMacroAction( const QByteArray& )));

Check warning on line 135 in src/Gui/DlgActionsImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

topLevel, SIGNAL(removeMacroAction( const QByteArray& )));
disconnect(this, SIGNAL(modifyMacroAction( const QByteArray& )),
topLevel, SIGNAL(modifyMacroAction( const QByteArray& )));
}
Expand Down Expand Up @@ -409,7 +409,6 @@
QStringList names = BitmapFactory().findIconFiles();
for (const auto & name : names) {
item = new QListWidgetItem(ui->listWidget);
//item->setIcon(QIcon(*it));
item->setIcon(QIcon(BitmapFactory().pixmap((const char*)name.toUtf8())));
item->setText(QFileInfo(name).baseName());
item->setToolTip(name);
Expand Down
3 changes: 0 additions & 3 deletions src/Gui/DownloadItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,6 @@ void DownloadItem::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)

void DownloadItem::updateInfoLabel()
{
//if (m_reply->error() == QNetworkReply::NoError)
// return;

qint64 bytesTotal = progressBar->maximum();
bool running = !downloadedSuccessfully();

Expand Down
75 changes: 5 additions & 70 deletions src/Gui/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,6 @@

try {
if (item->type() == TreeWidget::DocumentType) {
//QTreeWidget::mouseDoubleClickEvent(event);
Gui::Document* doc = static_cast<DocumentItem*>(item)->document();
if (!doc)
return;
Expand Down Expand Up @@ -2691,19 +2690,6 @@
void TreeWidget::drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const
{
QTreeWidget::drawRow(painter, options, index);
// Set the text and highlighted text color of a hidden object to a dark
//QTreeWidgetItem * item = itemFromIndex(index);
//if (item->type() == ObjectType && !(static_cast<DocumentObjectItem*>(item)->previousStatus & 1)) {
// QStyleOptionViewItem opt(options);
// opt.state ^= QStyle::State_Enabled;
// QColor c = opt.palette.color(QPalette::Inactive, QPalette::Dark);
// opt.palette.setColor(QPalette::Inactive, QPalette::Text, c);
// opt.palette.setColor(QPalette::Inactive, QPalette::HighlightedText, c);
// QTreeWidget::drawRow(painter, opt, index);
//}
//else {
// QTreeWidget::drawRow(painter, options, index);
//}
}

void TreeWidget::slotNewDocument(const Gui::Document& Doc, bool isMainDoc)
Expand All @@ -2718,16 +2704,6 @@
DocumentMap[&Doc] = item;
}

void TreeWidget::slotStartOpenDocument() {
// No longer required. Visibility is now handled inside onUpdateStatus() by
// UpdateDisabler.
//
// setVisible(false);
}

void TreeWidget::slotFinishOpenDocument() {
// setVisible(true);
}

void TreeWidget::onReloadDoc() {
if (!this->contextItem || this->contextItem->type() != DocumentType)
Expand Down Expand Up @@ -2842,11 +2818,11 @@
focus = widget.hasFocus();
visible = widget.isVisible();
if (visible) {
// setUpdatesEnabled(false) does not seem to speed up anything.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is an important comment that should be kept. The rest of the PR is OK.

// setVisible(false) on the other hand makes QTreeWidget::setData
// (i.e. any change to QTreeWidgetItem) faster by 10+ times.
//
// widget.setUpdatesEnabled(false);
// setUpdatesEnabled(false) does not seem to speed up anything.
// setVisible(false) on the other hand makes QTreeWidget::setData
// (i.e. any change to QTreeWidgetItem) faster by 10+ times.
//
// widget.setUpdatesEnabled(false);

widget.setVisible(false);
}
Expand All @@ -2857,7 +2833,6 @@

if (visible) {
widget.setVisible(true);
// widget.setUpdatesEnabled(true);
if (focus)
widget.setFocus();
}
Expand Down Expand Up @@ -4544,21 +4519,6 @@
return this->pDocument;
}

//void DocumentItem::markItem(const App::DocumentObject* Obj,bool mark)
//{
// // never call without Object!
// assert(Obj);
//
//
// std::map<std::string,DocumentObjectItem*>::iterator pos;
// pos = ObjectMap.find(Obj);
// if (pos != ObjectMap.end()) {
// QFont f = pos->second->font(0);
// f.setUnderline(mark);
// pos->second->setFont(0,f);
// }
//}

void DocumentItem::testStatus()
{
for (const auto& v : ObjectMap)
Expand Down Expand Up @@ -4670,33 +4630,8 @@
if (!subname.empty()) {
auto parentItem = item->getParentItem();
assert(parentItem);
if (selected && parentItem->selected) {
// When a group item is selected, all its children objects are
// highlighted in the 3D view. So, when an item of some group is
// newly selected, we must force unselect its parent in order to
// show the selection highlight. Besides, select both the parent
// group and its children doesn't make much sense.
//
// UPDATE: There are legit use case of both parent and child
// selection, for example, to disambiguate under which group to
// operate on the child.
//
// TREE_TRACE("force unselect parent");
// parentItem->setSelected(false);
// updateItemSelection(parentItem);
}
}

if (selected && item->isGroup()) {
// Same reasoning as above. When a group item is newly selected, We
// choose to force unselect all its children to void messing up the
// selection highlight
//
// UPDATE: same as above, child and parent selection is now re-enabled.
//
// TREE_TRACE("force unselect all children");
// updateSelection(item,true);
}

if (!selected) {
Gui::Selection().rmvSelection(docname, objname, subname.c_str());
Expand Down Expand Up @@ -5396,7 +5331,7 @@

// Prepend the visibility pixmap to the final icon pixmaps and use these as the icon.
QIcon new_icon;
for (auto state: {QIcon::On, QIcon::Off}) {

Check warning on line 5334 in src/Gui/Tree.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing space around colon in range-based for loop [whitespace/forcolon] [2]
QPixmap px_org = icon.pixmap(0xFFFF, 0xFFFF, QIcon::Normal, state);

QPixmap px(2*px_org.width(), px_org.height());
Expand Down Expand Up @@ -5762,4 +5697,4 @@
}
}

#include "moc_Tree.cpp"

Check failure on line 5700 in src/Gui/Tree.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'moc_Tree.cpp' file not found [clang-diagnostic-error]