Mis upgrades for the selection window - fixes #1737

* Added a search box that searches through object labels
* Added a context menu to selected items
* Allow to double-click an item to isolate
This commit is contained in:
Yorik van Havre 2014-09-13 12:02:45 -03:00
parent 7318a1d443
commit ce0f2452c8
6 changed files with 1531 additions and 15 deletions

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -61,6 +61,7 @@
<file>edit-redo.svg</file>
<file>edit-undo.svg</file>
<file>edit-edit.svg</file>
<file>edit-cleartext.svg</file>
<file>help-browser.svg</file>
<file>preferences-system.svg</file>
<file>process-stop.svg</file>
@ -70,6 +71,7 @@
<file>applications-python.svg</file>
<file>accessories-text-editor.svg</file>
<file>internet-web-browser.svg</file>
<file>view-select.svg</file>
<file>view-unselectable.svg</file>
<file>view-refresh.svg</file>
<file>view-fullscreen.svg</file>

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2980"
sodipodi:version="0.32"
inkscape:version="0.48.5 r10040"
sodipodi:docname="view-unselectable.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
id="defs2982">
<linearGradient
id="linearGradient3864">
<stop
id="stop3866"
offset="0"
style="stop-color:#71b2f8;stop-opacity:1;" />
<stop
id="stop3868"
offset="1"
style="stop-color:#002795;stop-opacity:1;" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective2988" />
<inkscape:perspective
id="perspective2872"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective2902"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective2902-9"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.75"
inkscape:cx="-28.52788"
inkscape:cy="4.7563882"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1053"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2985">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
inkscape:connector-curvature="0"
style="opacity:0.62000002;color:#000000;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 21.903211,22.639937 9.506983,6.86285 L 14.849835,53.787796 26.753863,61.905353 43.31422,37.620344 53.548475,45.028647 58.175009,4.8977691 21.903211,22.639937 z"
id="rect2925-0"
sodipodi:nodetypes="cccccccc" />
<path
style="color:#000000;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 15.493231,20.991587 9.506983,6.86285 L 8.4398554,52.139446 20.343883,60.257003 36.90424,35.971994 47.138495,43.380297 51.765029,3.2494191 15.493231,20.991587 z"
id="rect2925"
sodipodi:nodetypes="cccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -13,8 +13,8 @@
height="64px"
id="svg2980"
sodipodi:version="0.32"
inkscape:version="0.47 r22583"
sodipodi:docname="Tree_Unselectable.svg"
inkscape:version="0.48.5 r10040"
sodipodi:docname="view-unselectable.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
@ -67,17 +67,17 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7.7781746"
inkscape:cx="24.692695"
inkscape:cx="4.4437281"
inkscape:cy="31.499963"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="758"
inkscape:window-width="1920"
inkscape:window-height="1053"
inkscape:window-x="0"
inkscape:window-y="19"
inkscape:window-maximized="0" />
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2985">
<rdf:RDF>
@ -86,7 +86,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -95,11 +95,9 @@
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
style="color:#000000;fill:#858585;fill-opacity:1;fill-rule:evenodd;stroke:#606060;stroke-width:5;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
style="color:#000000;fill:#858585;fill-opacity:1;fill-rule:evenodd;stroke:#606060;stroke-width:5;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;opacity:0.62727273"
d="m 15.493231,20.991587 9.506983,6.86285 L 8.4398554,52.139446 20.343883,60.257003 36.90424,35.971994 47.138495,43.380297 51.765029,3.2494191 15.493231,20.991587 z"
id="rect2925"
sodipodi:nodetypes="cccccccc" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -26,15 +26,19 @@
# include <QVBoxLayout>
# include <QListWidget>
# include <QListWidgetItem>
# include <QLineEdit>
# include <QToolButton>
# include <QMenu>
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <App/Document.h>
#include "SelectionView.h"
#include "Command.h"
#include "Application.h"
#include "Document.h"
#include "ViewProvider.h"
#include "BitmapFactory.h"
@ -53,11 +57,29 @@ SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
pLayout->setSpacing( 0 );
pLayout->setMargin ( 0 );
QLineEdit* searchBox = new QLineEdit(this);
searchBox->setPlaceholderText( tr( "Search" ) );
searchBox->setToolTip( tr( "Searches object labels" ) );
pLayout->addWidget( searchBox );
QHBoxLayout* llayout = new QHBoxLayout(searchBox);
QToolButton* clearButton = new QToolButton(searchBox);
clearButton->setFixedSize(18, 21);
clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet(QString::fromAscii("QToolButton {margin-bottom:6px}"));
clearButton->setIcon(BitmapFactory().pixmap(":/icons/edit-cleartext.svg"));
clearButton->setToolTip( tr( "Clears the search field" ) );
llayout->addWidget(clearButton,0,Qt::AlignRight);
selectionView = new QListWidget(this);
pLayout->addWidget( selectionView);
selectionView->setContextMenuPolicy(Qt::CustomContextMenu);
pLayout->addWidget( selectionView );
resize( 200, 200 );
QObject::connect(clearButton, SIGNAL(clicked()), searchBox, SLOT(clear()));
QObject::connect(searchBox, SIGNAL(textChanged(QString)), this, SLOT(search(QString)));
QObject::connect(selectionView, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(select(QListWidgetItem*)));
QObject::connect(selectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onItemContextMenu(QPoint)));
Gui::Selection().Attach(this);
}
@ -81,7 +103,12 @@ void SelectionView::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
temp += ".";
temp += Reason.pSubName;
}
App::Document* doc = App::GetApplication().getDocument(Reason.pDocName);
App::DocumentObject* obj = doc->getObject(Reason.pObjectName);
temp += " (";
temp += obj->Label.getValue();
temp += ")";
new QListWidgetItem(QString::fromAscii(temp.c_str()), selectionView);
}
else if (Reason.Type == SelectionChanges::ClrSelection) {
@ -97,6 +124,11 @@ void SelectionView::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
temp += ".";
temp += Reason.pSubName;
}
App::Document* doc = App::GetApplication().getDocument(Reason.pDocName);
App::DocumentObject* obj = doc->getObject(Reason.pObjectName);
temp += " (";
temp += obj->Label.getValue();
temp += ")";
// remove all items
QList<QListWidgetItem *> l = selectionView->findItems(QLatin1String(temp.c_str()),Qt::MatchExactly);
@ -117,11 +149,98 @@ void SelectionView::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
temp += ".";
temp += it->SubName;
}
App::Document* doc = App::GetApplication().getDocument(it->DocName);
App::DocumentObject* obj = doc->getObject(it->FeatName);
temp += " (";
temp += obj->Label.getValue();
temp += ")";
new QListWidgetItem(QString::fromAscii(temp.c_str()), selectionView);
}
}
}
void SelectionView::search(QString text)
{
if (!text.isEmpty()) {
App::Document* doc = App::GetApplication().getActiveDocument();
std::vector<App::DocumentObject*> objects;
if (doc) {
Gui::Selection().clearSelection();
objects = doc->getObjects();
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
QString label = QString::fromUtf8((*it)->Label.getValue());
if (label.contains(text,Qt::CaseInsensitive)) {
if (!Gui::Selection().hasSelection((*it)->getNameInDocument())) {
Gui::Selection().addSelection(doc->getName(),(*it)->getNameInDocument(),0);
}
}
}
}
}
}
void SelectionView::select(QListWidgetItem* item)
{
if (!item)
item = selectionView->currentItem();
if (!item)
return;
QStringList elements = item->text().split(QString::fromAscii("."));
// remove possible space from object name followed by label
elements[1] = elements[1].split(QString::fromAscii(" "))[0];
//Gui::Selection().clearSelection();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.Selection.clearSelection()");
//Gui::Selection().addSelection(elements[0].toAscii(),elements[1].toAscii(),0);
QString cmd = QString::fromAscii("Gui.Selection.addSelection(App.getDocument(\"%1\").getObject(\"%2\"))").arg(elements[0]).arg(elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toAscii());
}
void SelectionView::deselect(void)
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
return;
QStringList elements = item->text().split(QString::fromAscii("."));
// remove possible space from object name followed by label
elements[1] = elements[1].split(QString::fromAscii(" "))[0];
//Gui::Selection().rmvSelection(elements[0].toAscii(),elements[1].toAscii(),0);
QString cmd = QString::fromAscii("Gui.Selection.removeSelection(App.getDocument(\"%1\").getObject(\"%2\"))").arg(elements[0]).arg(elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toAscii());
}
void SelectionView::zoom(void)
{
select();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.SendMsgToActiveView(\"ViewSelection\")");
}
void SelectionView::treeSelect(void)
{
select();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.runCommand(\"Std_TreeSelection\")");
}
void SelectionView::onItemContextMenu(QPoint point)
{
QListWidgetItem *item = selectionView->itemAt(point);
if (!item)
return;
QMenu *menu = new QMenu;
QAction *selectAction = menu->addAction(tr("Select only"),this,SLOT(select()));
selectAction->setIcon(QIcon(QString::fromAscii(":/icons/view-select.svg")));
selectAction->setToolTip(tr("Selects only this object"));
QAction *deselectAction = menu->addAction(tr("Deselect"),this,SLOT(deselect()));
deselectAction->setIcon(QIcon(QString::fromAscii(":/icons/view-unselectable.svg")));
deselectAction->setToolTip(tr("Deselects this object"));
QAction *zoomAction = menu->addAction(tr("Zoom fit"),this,SLOT(zoom()));
zoomAction->setIcon(QIcon(QString::fromAscii(":/icons/view-zoom-fit.svg")));
zoomAction->setToolTip(tr("Selects and fits this object in the 3D window"));
QAction *gotoAction = menu->addAction(tr("Go to selection"),this,SLOT(treeSelect()));
gotoAction->setToolTip(tr("Selects and locates this object in the tree view"));
menu->exec(selectionView->mapToGlobal(point));
}
void SelectionView::onUpdate(void)
{
}

View File

@ -83,6 +83,18 @@ public:
virtual void onUpdate(void);
QListWidget* selectionView;
public Q_SLOTS:
/// get called when text is entered in the search box
void search(QString text);
/// get called when the list is right-clicked
void onItemContextMenu(QPoint point);
/// different actions
void select(QListWidgetItem* item=0);
void deselect(void);
void zoom(void);
void treeSelect(void);
};
} // namespace DockWnd