33 "DlgSettingsCurveList",
35 m_curveNameList (nullptr)
48void DlgSettingsCurveList::appendCurveName (
const QString &curveNameNew,
49 const QString &curveNameOriginal,
53 <<
" curve=" << curveNameNew.toLatin1().data();
57 int row = m_curveNameList->
rowCount ();
64void DlgSettingsCurveList::createButtons (QGridLayout *layout,
69 m_btnAdd =
new QPushButton (tr (
"Add..."));
70 m_btnAdd->setWhatsThis (tr (
"Adds a new curve to the curve list. The curve name can be edited in the curve name list.\n\n"
71 "Every curve name must be unique"));
72 m_btnAdd->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
73 connect (m_btnAdd, SIGNAL (released ()),
this, SLOT (slotNew()));
74 layout->addWidget (m_btnAdd, row, 1, 1, 1, Qt::AlignLeft);
76 m_btnRemove =
new QPushButton (tr (
"Remove"));
77 m_btnRemove->setWhatsThis (tr (
"Removes the currently selected curve from the curve list.\n\n"
78 "There must always be at least one curve"));
79 m_btnRemove->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
80 connect (m_btnRemove, SIGNAL (released ()),
this, SLOT (slotRemove()));
81 layout->addWidget (m_btnRemove, row++, 2, 1, 1, Qt::AlignRight);
84void DlgSettingsCurveList::createListCurves (QGridLayout *layout,
89 QLabel *label =
new QLabel (QString (
"%1:").arg (tr (
"Curve Names")));
90 layout->addWidget (label, row++, 1);
93 m_listCurves =
new QListView;
94 m_listCurves->setWhatsThis (tr (
"List of the curves belonging to this document.\n\n"
95 "Click on a curve name to edit it. Each curve name must be unique.\n\n"
96 "Reorder curves by dragging them around."));
97 m_listCurves->setMinimumHeight (200);
98 m_listCurves->setSelectionBehavior (QAbstractItemView::SelectItems);
99 m_listCurves->setDragDropOverwriteMode (
false);
100 m_listCurves->setSelectionMode (QAbstractItemView::SingleSelection);
101 m_listCurves->setDefaultDropAction (Qt::MoveAction);
102 m_listCurves->setDragDropOverwriteMode (
false);
103 m_listCurves->setDragEnabled (
true);
104 m_listCurves->setDropIndicatorShown (
true);
105 m_listCurves->setDragDropMode (QAbstractItemView::InternalMove);
106 layout->addWidget (m_listCurves, row++, 1, 1, 2);
109 connect (m_curveNameList, SIGNAL (rowsAboutToBeRemoved (
const QModelIndex &,
int,
int)),
111 connect (m_curveNameList, SIGNAL (dataChanged (
const QModelIndex &,
const QModelIndex &,
const QVector<int> &)),
112 this, SLOT (slotDataChanged (
const QModelIndex &,
const QModelIndex &,
const QVector<int> &)));
114 m_listCurves->setModel (m_curveNameList);
121 m_btnSaveDefault =
new QPushButton (tr (
"Save As Default"));
122 m_btnSaveDefault->setWhatsThis (tr (
"Save the curve names for use as defaults for future graph curves."));
123 connect (m_btnSaveDefault, SIGNAL (released ()),
this, SLOT (slotSaveDefault ()));
124 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
126 m_btnResetDefault =
new QPushButton (tr (
"Reset Default"));
127 m_btnResetDefault->setWhatsThis (tr (
"Reset the defaults for future graph curves to the original settings."));
128 connect (m_btnResetDefault, SIGNAL (released ()),
this, SLOT (slotResetDefault()));
129 layout->addWidget (m_btnResetDefault, 0, Qt::AlignRight);
131 QSpacerItem *spacer =
new QSpacerItem (40, 2);
132 layout->addItem (spacer);
139 const int EMPTY_COLUMN_WIDTH = 30;
141 QWidget *subPanel =
new QWidget ();
142 QGridLayout *layout =
new QGridLayout (subPanel);
143 subPanel->setLayout (layout);
146 createListCurves (layout, row);
147 createButtons (layout, row);
149 layout->setColumnStretch (0, 0);
150 layout->setColumnMinimumWidth (0, EMPTY_COLUMN_WIDTH);
151 layout->setColumnStretch (1, 1);
152 layout->setColumnStretch (2, 1);
153 layout->setColumnStretch (3, 0);
154 layout->setColumnMinimumWidth (3, EMPTY_COLUMN_WIDTH);
159bool DlgSettingsCurveList::endsWithNumber (
const QString &str)
const
161 bool success =
false;
163 if (!str.isEmpty ()) {
165 success = (str.right (1).at (0).digitValue() >= 0);
183void DlgSettingsCurveList::insertCurveName (
int row,
184 const QString &curveNameNew,
185 const QString &curveNameOriginal,
192 unsigned (numPoints));
202 m_listCurves->reset ();
203 m_curveNameList->
reset ();
206 QStringList::const_iterator itr;
207 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
208 QString curveName = *itr;
209 appendCurveName (curveName,
214 selectCurveName (curveNames.first());
220int DlgSettingsCurveList::newRowFromSelection ()
const
222 int numSelectedItems = m_listCurves->selectionModel ()->selectedIndexes ().count ();
223 int numItems = m_listCurves->model ()->rowCount ();
227 if ((numSelectedItems == 0) &&
233 }
else if (numSelectedItems == 1) {
236 newRow = 1 + m_listCurves->selectionModel ()->selectedIndexes ().at (0).row ();
243QString DlgSettingsCurveList::nextCurveName ()
const
245 const QString DASH_ONE (
"-1");
249 int newRow = newRowFromSelection ();
250 int numItems = m_listCurves->model ()->rowCount ();
253 QString curveNameBefore, curveNameAfter;
256 QModelIndex index = m_curveNameList->index (newRow - 1, 0);
257 curveNameBefore = m_curveNameList->data (index).toString ();
261 if ((0 <= newRow) && (newRow < numItems)) {
263 QModelIndex index = m_curveNameList->index (newRow, 0);
264 curveNameAfter = m_curveNameList->data (index).toString ();
269 QString curveNameNext;
270 if (curveNameBefore.isEmpty () && !curveNameAfter.isEmpty () && endsWithNumber (curveNameAfter)) {
273 int numberAfter = numberAtEnd (curveNameAfter);
274 int numberNew = numberAfter - 1;
275 int pos = curveNameAfter.lastIndexOf (QString::number (numberAfter));
278 curveNameNext = QString (
"%1%2")
279 .arg (curveNameAfter.left (pos))
284 curveNameNext = curveNameAfter;
288 }
else if (curveNameBefore.isEmpty ()) {
294 curveNameNext = curveNameBefore;
296 if (endsWithNumber (curveNameBefore)) {
299 int numberBefore = numberAtEnd (curveNameBefore);
300 int numberNew = numberBefore + 1;
301 int pos = curveNameBefore.lastIndexOf (QString::number (numberBefore));
304 curveNameNext = QString (
"%1%2")
305 .arg (curveNameBefore.left (pos))
307 if (curveNameNext == curveNameAfter) {
310 curveNameNext = QString (
"%1%2")
311 .arg (curveNameBefore)
320 int indexOneBasedNext = numItems + 1;
328 curveNameNext += DASH_ONE;
331 return curveNameNext;
334int DlgSettingsCurveList::numberAtEnd (
const QString &str)
const
340 int ch = str.size () - 1;
341 while (str.at (ch).digitValue() >= 0) {
350 return sign * str.mid (ch).toInt ();
353unsigned int DlgSettingsCurveList::numPointsForSelectedCurves ()
const
355 QList<unsigned int > rowsSelected;
358 for (
int i = 0; i < m_listCurves->selectionModel()->selectedIndexes ().count (); i++) {
360 int row = m_listCurves->selectionModel()->selectedIndexes ().at (i).row ();
361 rowsSelected << unsigned (row);
367void DlgSettingsCurveList::printStream(QTextStream &str)
const
372void DlgSettingsCurveList::removeSelectedCurves ()
376 ENGAUGE_ASSERT (m_listCurves->selectionModel ()->selectedIndexes ().count () > 0);
379 QString firstCurveAfter;
380 for (
int row = m_listCurves->model()->rowCount() - 1; row >= 0; row--) {
383 if (indexCurrent == m_listCurves->selectionModel()->selectedIndexes().last()) {
389 firstCurveAfter = indexCurrent.data().toString();
393 for (
int i = m_listCurves->selectionModel ()->selectedIndexes ().count () - 1; i >= 0; i--) {
395 int row = m_listCurves->selectionModel ()->selectedIndexes ().at (i).row ();
397 m_curveNameList->removeRow (row);
400 if (firstCurveAfter.isEmpty ()) {
403 int numItems = m_listCurves->model()->rowCount();
405 firstCurveAfter = m_listCurves->model()->data (indexLast).toString();
410 selectCurveName(firstCurveAfter);
413void DlgSettingsCurveList::selectCurveName (
const QString &curveWanted)
416 <<
" curve=" << curveWanted.toLatin1().data();
418 for (
int row = 0; row < m_listCurves->model()->rowCount(); row++) {
421 QString curveGot = index.data ().toString ();
423 if (curveWanted == curveGot) {
426 m_listCurves->setCurrentIndex (index);
440void DlgSettingsCurveList::slotDataChanged (
const QModelIndex &topLeft,
441 const QModelIndex &bottomRight,
442 const QVector<int> &roles)
447 QString curveEntries;
448 QTextStream str (&curveEntries);
452 <<
" topLeft=(" << topLeft.row () <<
"," << topLeft.column () <<
")"
453 <<
" bottomRight=(" << bottomRight.row () <<
"," << bottomRight.column () <<
")"
455 <<
" defaultDragOption=" << (m_listCurves->defaultDropAction() == Qt::MoveAction ?
"MoveAction" :
"CopyAction")
456 <<
" curveEntries=(" << curveEntries.toLatin1().data() <<
")";
466 <<
" parentValid=" << (parent.isValid() ?
"yes" :
"no")
467 <<
" rowFirst=" << rowFirst
468 <<
" rowLast=" << rowLast;
473void DlgSettingsCurveList::slotNew ()
477 const QString NO_ORIGINAL_CURVE_NAME;
478 const int NO_POINTS = 0;
480 QString curveNameSuggestion = nextCurveName ();
482 int row = newRowFromSelection();
484 insertCurveName (row,
486 NO_ORIGINAL_CURVE_NAME,
489 selectCurveName (curveNameSuggestion);
494void DlgSettingsCurveList::slotRemove ()
499 int numPoints = signed (numPointsForSelectedCurves ());
501 int rtn = QMessageBox::Ok;
505 if (m_listCurves->selectionModel ()->selectedIndexes ().count () == 1) {
506 msg = QString (
"%1 %2 %3")
507 .arg (tr (
"Removing this curve will also remove"))
509 .arg (tr (
"points. Continue?"));
511 msg = QString (
"%1 %2 %3")
512 .arg (tr (
"Removing these curves will also remove"))
514 .arg (tr (
"points. Continue?"));
517 rtn = QMessageBox::warning (
nullptr,
518 tr (
"Curves With Points"),
521 QMessageBox::Cancel);
524 if (rtn == QMessageBox::Ok) {
525 removeSelectedCurves ();
531void DlgSettingsCurveList::slotResetDefault()
535 const QString REMOVE_ALL_SETTINGS_IN_GROUP;
539 int indexOneBased = 1;
543 while (settings.childGroups().contains (groupName)) {
545 settings.beginGroup (groupName);
546 settings.remove (REMOVE_ALL_SETTINGS_IN_GROUP);
547 settings.endGroup ();
554void DlgSettingsCurveList::slotSaveDefault()
560 for (
int row = 0; row < m_curveNameList->
rowCount (); row++) {
562 QModelIndex idxCurrent = m_curveNameList->index (row, 0);
564 QString curveNameCurrent = m_curveNameList->data (idxCurrent).toString ();
566 int indexOneBased = row + 1;
571 settings.beginGroup (groupName);
574 settings.endGroup ();
578void DlgSettingsCurveList::updateControls ()
586 int numSelectedItems = m_listCurves->selectionModel ()->selectedIndexes ().count ();
587 int numItems = m_curveNameList->
rowCount ();
590 m_btnRemove->setEnabled ((numSelectedItems > 0) && (numSelectedItems < numItems));
@ CURVE_NAME_LIST_COLUMN_CURRENT
const QString DEFAULT_GRAPH_CURVE_NAME
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
#define ENGAUGE_CHECK_PTR(ptr)
#endif
log4cpp::Category * mainCat
QString rolesAsString(const QVector< int > &roles)
const QString SETTINGS_ENGAUGE
const QString SETTINGS_DIGITIZER
const QString SETTINGS_CURVE_NAME
Command for DlgSettingsCurveList.
Model for DlgSettingsCurveList and CmdSettingsCurveList.
void reset()
Clear all information.
bool containsCurveNameCurrent(const QString &curveName) const
Return true if specified curve name is already in the list.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.
QString currentCurvesAsString() const
For debugging we dump the curve names.
unsigned int numPointsForSelectedCurves(const QList< unsigned int > &rowsSelected) const
Return the number of points associated with the selected curves, as specified by their row numbers.
void insertRow(int row, const QString &curveCurrent, const QString &curveOriginal, unsigned int pointCount)
Create a new entry at the specified row.
Abstract base class for all Settings dialogs.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
MainWindow & mainWindow()
Get method for MainWindow.
DlgSettingsCurveList(MainWindow &mainWindow)
Single constructor.
void slotRowsAboutToBeRemoved(const QModelIndex &parent, int rowFirst, int rowLast)
Cleanup after rows have been removed in the model. We remove the corresponding rows in the QListView.
virtual void handleOk()
Process slotOk.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual ~DlgSettingsCurveList()
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Manage storage and retrieval of the settings for the curves.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
QString defaultCurveName(int indexOneBased, const QString &defaultName) const
Default graph name for the specified curve index.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)