src/gui_editactions.cpp

changeset 190
82f784cf2ce5
parent 189
ac2d3e8dd110
child 191
9bb6a17305ad
equal deleted inserted replaced
189:ac2d3e8dd110 190:82f784cf2ce5
25 #include "setContentsDialog.h" 25 #include "setContentsDialog.h"
26 #include "misc.h" 26 #include "misc.h"
27 #include "bbox.h" 27 #include "bbox.h"
28 #include "radiobox.h" 28 #include "radiobox.h"
29 #include "extprogs.h" 29 #include "extprogs.h"
30 #include "checkboxgroup.h"
30 #include <qspinbox.h> 31 #include <qspinbox.h>
31 #include <qcheckbox.h> 32 #include <qcheckbox.h>
32 33
33 vector<LDObject*> g_Clipboard; 34 vector<LDObject*> g_Clipboard;
34 35
752 } 753 }
753 754
754 // ========================================================================================================================================= 755 // =========================================================================================================================================
755 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 756 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
756 // ========================================================================================================================================= 757 // =========================================================================================================================================
758 class ReplaceCoordsDialog : public QDialog {
759 public:
760 explicit ReplaceCoordsDialog (QWidget* parent = null, Qt::WindowFlags f = 0) : QDialog (parent, f) {
761 cbg_axes = new CheckBoxGroup<Axis> ("Axes", Qt::Horizontal);
762 cbg_axes->addCheckBox ("X", X);
763 cbg_axes->addCheckBox ("Y", Y);
764 cbg_axes->addCheckBox ("Z", Z);
765
766 lb_search = new QLabel ("Search:");
767 lb_replacement = new QLabel ("Replacement:");
768
769 dsb_search = new QDoubleSpinBox;
770 dsb_search->setRange (-10000.0f, 10000.0f);
771
772 dsb_replacement = new QDoubleSpinBox;
773 dsb_replacement->setRange (-10000.0f, 10000.0f);
774
775 QGridLayout* valueLayout = new QGridLayout;
776 valueLayout->setColumnStretch (1, 1);
777 valueLayout->addWidget (lb_search, 0, 0);
778 valueLayout->addWidget (dsb_search, 0, 1);
779 valueLayout->addWidget (lb_replacement, 1, 0);
780 valueLayout->addWidget (dsb_replacement, 1, 1);
781
782 QVBoxLayout* layout = new QVBoxLayout;
783 layout->addWidget (cbg_axes);
784 layout->addLayout (valueLayout);
785 layout->addWidget (makeButtonBox (*this));
786 setLayout (layout);
787 }
788
789 std::vector<Axis> axes () const {
790 return cbg_axes->checkedValues ();
791 }
792
793 double searchValue () { return dsb_search->value (); }
794 double replacementValue () { return dsb_replacement->value (); }
795
796 private:
797 CheckBoxGroup<Axis>* cbg_axes;
798 QLabel* lb_search, *lb_replacement;
799 QDoubleSpinBox* dsb_search, *dsb_replacement;
800 };
801
802 // =========================================================================================================================================
757 MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) { 803 MAKE_ACTION (replaceCoords, "Replace Coordinates", "replace-coords", "Find and replace coordinate values", CTRL (R)) {
758 QDialog dlg; 804 ReplaceCoordsDialog dlg;
759 } 805
806 if (!dlg.exec ())
807 return;
808
809 const double search = dlg.searchValue (),
810 replacement = dlg.replacementValue ();
811 vector<Axis> sel = dlg.axes ();
812
813 EditHistory* history = new EditHistory;
814
815 for (LDObject* obj : g_win->sel ()) {
816 bool altered = false;
817 LDObject* copy = obj->clone ();
818
819 for (short i = 0; i < obj->vertices (); ++i)
820 for (Axis ax : sel) {
821 if (obj->coords[i][ax] == search) {
822 obj->coords[i][ax] = replacement;
823 altered = true;
824 }
825 }
826
827 if (altered)
828 history->addEntry (copy, obj, obj->getIndex (g_curfile));
829
830 delete copy;
831 }
832
833 History::addEntry (history);
834 g_win->refresh ();
835 }

mercurial