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

Auto scroll to constraint on click #18859

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
#include "TaskSketcherConstraints.h"
#include "Utils.h"
#include "ViewProviderSketch.h"
#include "ui_TaskSketcherConstraints.h"

Check failure on line 56 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'ui_TaskSketcherConstraints.h' file not found [clang-diagnostic-error]


// clang-format off
using namespace SketcherGui;

Check warning on line 60 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]
using namespace Gui::TaskView;

Check warning on line 61 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]
namespace sp = std::placeholders;

// Translation block for context menu: do not remove
#if 0

Check warning on line 65 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
QT_TRANSLATE_NOOP("SketcherGui::ConstraintView", "Select Elements");
#endif

Expand All @@ -72,9 +72,9 @@
/// CMDSTR is the string registered in the commandManager
/// FUNC is the name of the member function to be executed on selection of the menu item
/// ACTSONSELECTION is a true/false value to activate the command only if a selection is made
#define CONTEXT_ITEM(ICONSTR, NAMESTR, CMDSTR, FUNC, ACTSONSELECTION) \

Check warning on line 75 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

function-like macro 'CONTEXT_ITEM' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]
QIcon icon_##FUNC(Gui::BitmapFactory().pixmap(ICONSTR)); \
QAction* constr_##FUNC = menu.addAction(icon_##FUNC, tr(NAMESTR), this, SLOT(FUNC())); \

Check warning on line 77 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

QAction* constr_##FUNC = menu.addAction(icon_##FUNC, tr(NAMESTR), this, SLOT(FUNC())); \
constr_##FUNC->setShortcut(QKeySequence(QString::fromUtf8( \
Gui::Application::Instance->commandManager().getCommandByName(CMDSTR)->getAccel()))); \
if (ACTSONSELECTION) \
Expand All @@ -82,14 +82,14 @@
else \
constr_##FUNC->setEnabled(true);
/// Defines the member function corresponding to the CONTEXT_ITEM macro
#define CONTEXT_MEMBER_DEF(CMDSTR, FUNC) \

Check warning on line 85 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

function-like macro 'CONTEXT_MEMBER_DEF' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]
void ConstraintView::FUNC() \
{ \
Gui::Application::Instance->commandManager().runCommandByName(CMDSTR); \
}

// helper class to store additional information about the listWidget entry.
class ConstraintItem: public QListWidgetItem

Check warning on line 92 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'ConstraintItem' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
{
public:
ConstraintItem(const Sketcher::SketchObject* s, ViewProviderSketch* sketchview, int ConstNbr)
Expand All @@ -102,17 +102,17 @@

updateVirtualSpaceStatus();
}
~ConstraintItem() override

Check warning on line 105 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use '= default' to define a trivial destructor [modernize-use-equals-default]
{}
void setData(int role, const QVariant& value) override
{
if (role == Qt::EditRole)

Check warning on line 109 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
this->value = value;

QListWidgetItem::setData(role, value);
}

QVariant data(int role) const override

Check warning on line 115 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

function 'data' has cognitive complexity of 37 (threshold 25) [readability-function-cognitive-complexity]
{
if (ConstraintNbr < 0 || ConstraintNbr >= sketch->Constraints.getSize())
return QVariant();
Expand Down Expand Up @@ -701,7 +701,7 @@
}

std::stringstream ss;
ss << "DummyConstraint" << rand();

Check warning on line 704 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Consider using rand_r(...) instead of rand(...) for improved thread safety. [runtime/threadsafe_fn] [2]
std::string tmpname = ss.str();

Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Swap constraint names"));
Expand Down Expand Up @@ -1371,6 +1371,10 @@
auto tmpBlock = ui->listWidgetConstraints->blockSignals(true);
item->setSelected(select);
ui->listWidgetConstraints->blockSignals(tmpBlock);
if (select && ui->listWidgetConstraints->model()) { // scrollTo only on select, not de-select
QModelIndex index = ui->listWidgetConstraints->model()->index(i, 0);
ui->listWidgetConstraints->scrollTo(index, QAbstractItemView::PositionAtCenter);
}
break;
}
}
Expand Down Expand Up @@ -1528,7 +1532,7 @@
}
stream << constrIds[constrIds.size() - 1] << ']';

std::string constrIdList = stream.str();

Check warning on line 1535 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Add #include <string> for string [build/include_what_you_use] [4]

try {
Gui::cmdAppObjectArgs(sketch,
Expand Down Expand Up @@ -1669,7 +1673,7 @@
assert(sketchView);
// Build up ListView with the constraints
const Sketcher::SketchObject* sketch = sketchView->getSketchObject();
const std::vector<Sketcher::Constraint*>& vals = sketch->Constraints.getValues();

Check warning on line 1676 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Add #include <vector> for vector<> [build/include_what_you_use] [4]

/* Update constraint number and virtual space check status */
for (int i = 0; i < ui->listWidgetConstraints->count(); ++i) {
Expand Down Expand Up @@ -1787,5 +1791,5 @@
}


#include "moc_TaskSketcherConstraints.cpp"

Check warning on line 1794 in src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Do not include .cpp files from other packages [build/include] [4]
// clang-format on
Loading