35 "DlgSettingsCurveList",
37 m_curveNameList (nullptr)
50void DlgSettingsCurveList::appendCurveName (
const QString &curveNameNew,
51 const QString &curveNameOriginal,
55 <<
" curve=" << curveNameNew.toLatin1().data();
59 int row = m_curveNameList->
rowCount ();
66void DlgSettingsCurveList::createButtons (QGridLayout *layout,
71 m_btnAdd =
new QPushButton (tr (
"Add..."));
72 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"
73 "Every curve name must be unique"));
74 m_btnAdd->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
75 connect (m_btnAdd, SIGNAL (released ()),
this, SLOT (slotNew()));
76 layout->addWidget (m_btnAdd, row, 1, 1, 1, Qt::AlignLeft);
78 m_btnRemove =
new QPushButton (tr (
"Remove"));
79 m_btnRemove->setWhatsThis (tr (
"Removes the currently selected curve from the curve list.\n\n"
80 "There must always be at least one curve"));
81 m_btnRemove->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
82 connect (m_btnRemove, SIGNAL (released ()),
this, SLOT (slotRemove()));
83 layout->addWidget (m_btnRemove, row++, 2, 1, 1, Qt::AlignRight);
86void DlgSettingsCurveList::createListCurves (QGridLayout *layout,
91 QLabel *label =
new QLabel (QString (
"%1:").arg (tr (
"Curve Names")));
92 layout->addWidget (label, row++, 1);
95 m_listCurves =
new QListView;
96 m_listCurves->setWhatsThis (tr (
"List of the curves belonging to this document.\n\n"
97 "Click on a curve name to edit it. Each curve name must be unique.\n\n"
98 "Reorder curves by dragging them around."));
99 m_listCurves->setMinimumHeight (200);
100 m_listCurves->setSelectionBehavior (QAbstractItemView::SelectItems);
101 m_listCurves->setDragDropOverwriteMode (
false);
102 m_listCurves->setSelectionMode (QAbstractItemView::SingleSelection);
103 m_listCurves->setDefaultDropAction (Qt::MoveAction);
104 m_listCurves->setDragDropOverwriteMode (
false);
105 m_listCurves->setDragEnabled (
true);
106 m_listCurves->setDropIndicatorShown (
true);
107 m_listCurves->setDragDropMode (QAbstractItemView::InternalMove);
108 layout->addWidget (m_listCurves, row, 1, 1, 2);
115 m_curveNameList =
new CurveNameList;
116 connect (m_curveNameList, SIGNAL (rowsAboutToBeRemoved (
const QModelIndex &,
int,
int)),
118 connect (m_curveNameList, SIGNAL (dataChanged (
const QModelIndex &,
const QModelIndex &,
const QVector<int> &)),
119 this, SLOT (slotDataChanged (
const QModelIndex &,
const QModelIndex &,
const QVector<int> &)));
121 m_listCurves->setModel (m_curveNameList);
128 m_btnSaveDefault =
new QPushButton (tr (
"Save As Default"));
129 m_btnSaveDefault->setWhatsThis (tr (
"Save the curve names for use as defaults for future graph curves."));
130 connect (m_btnSaveDefault, SIGNAL (released ()),
this, SLOT (slotSaveDefault ()));
131 layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
133 m_btnResetDefault =
new QPushButton (tr (
"Reset Default"));
134 m_btnResetDefault->setWhatsThis (tr (
"Reset the defaults for future graph curves to the original settings."));
135 connect (m_btnResetDefault, SIGNAL (released ()),
this, SLOT (slotResetDefault()));
136 layout->addWidget (m_btnResetDefault, 0, Qt::AlignRight);
138 QSpacerItem *spacer =
new QSpacerItem (40, 2);
139 layout->addItem (spacer);
146 const int EMPTY_COLUMN_WIDTH = 30;
148 QWidget *subPanel =
new QWidget ();
149 QGridLayout *layout =
new QGridLayout (subPanel);
150 subPanel->setLayout (layout);
153 createListCurves (layout, row);
154 createButtons (layout, row);
156 layout->setColumnStretch (0, 0);
157 layout->setColumnMinimumWidth (0, EMPTY_COLUMN_WIDTH);
158 layout->setColumnStretch (1, 1);
159 layout->setColumnStretch (2, 1);
160 layout->setColumnStretch (3, 0);
161 layout->setColumnMinimumWidth (3, EMPTY_COLUMN_WIDTH);
166bool DlgSettingsCurveList::endsWithNumber (
const QString &str)
const
168 bool success =
false;
170 if (!str.isEmpty ()) {
172 success = (str.right (1).at (0).digitValue() >= 0);
190void DlgSettingsCurveList::insertCurveName (
int row,
191 const QString &curveNameNew,
192 const QString &curveNameOriginal,
199 unsigned (numPoints));
209 m_listCurves->reset ();
210 m_curveNameList->reset ();
212 QStringList curveNames =
cmdMediator.curvesGraphsNames ();
213 QStringList::const_iterator itr;
214 for (itr = curveNames.begin (); itr != curveNames.end (); itr++) {
215 QString curveName = *itr;
216 appendCurveName (curveName,
221 selectCurveName (curveNames.first());
227int DlgSettingsCurveList::newRowFromSelection ()
const
229 int numSelectedItems = m_listCurves->selectionModel ()->selectedIndexes ().count ();
230 int numItems = m_listCurves->model ()->rowCount ();
234 if ((numSelectedItems == 0) &&
240 }
else if (numSelectedItems == 1) {
243 newRow = 1 + m_listCurves->selectionModel ()->selectedIndexes ().at (0).row ();
250QString DlgSettingsCurveList::nextCurveName ()
const
252 const QString DASH_ONE (
"-1");
256 int newRow = newRowFromSelection ();
257 int numItems = m_listCurves->model ()->rowCount ();
260 QString curveNameBefore, curveNameAfter;
263 QModelIndex index = m_curveNameList->index (newRow - 1, 0);
264 curveNameBefore = m_curveNameList->data (index).toString ();
268 if ((0 <= newRow) && (newRow < numItems)) {
270 QModelIndex index = m_curveNameList->index (newRow, 0);
271 curveNameAfter = m_curveNameList->data (index).toString ();
276 QString curveNameNext;
277 if (curveNameBefore.isEmpty () && !curveNameAfter.isEmpty () && endsWithNumber (curveNameAfter)) {
280 int numberAfter = numberAtEnd (curveNameAfter);
281 int numberNew = numberAfter - 1;
282 int pos = curveNameAfter.lastIndexOf (QString::number (numberAfter));
285 curveNameNext = QString (
"%1%2")
286 .arg (curveNameAfter.left (pos))
291 curveNameNext = curveNameAfter;
295 }
else if (curveNameBefore.isEmpty ()) {
301 curveNameNext = curveNameBefore;
303 if (endsWithNumber (curveNameBefore)) {
306 int numberBefore = numberAtEnd (curveNameBefore);
307 int numberNew = numberBefore + 1;
308 int pos = curveNameBefore.lastIndexOf (QString::number (numberBefore));
311 curveNameNext = QString (
"%1%2")
312 .arg (curveNameBefore.left (pos))
314 if (curveNameNext == curveNameAfter) {
317 curveNameNext = QString (
"%1%2")
318 .arg (curveNameBefore)
326 SettingsForGraph settingsForGraph;
327 int indexOneBasedNext = numItems + 1;
334 while (m_curveNameList->containsCurveNameCurrent (curveNameNext)) {
335 curveNameNext += DASH_ONE;
338 return curveNameNext;
341int DlgSettingsCurveList::numberAtEnd (
const QString &str)
const
347 int ch = str.size () - 1;
348 while (str.at (ch).digitValue() >= 0) {
357 return sign * str.mid (ch).toInt ();
360unsigned int DlgSettingsCurveList::numPointsForSelectedCurves ()
const
362 QList<unsigned int > rowsSelected;
365 for (
int i = 0; i < m_listCurves->selectionModel()->selectedIndexes ().count (); i++) {
367 int row = m_listCurves->selectionModel()->selectedIndexes ().at (i).row ();
368 rowsSelected << unsigned (row);
371 return m_curveNameList->numPointsForSelectedCurves (rowsSelected);
374void DlgSettingsCurveList::printStream(QTextStream &str)
const
376 str << m_curveNameList->currentCurvesAsString();
379void DlgSettingsCurveList::removeSelectedCurves ()
383 ENGAUGE_ASSERT (m_listCurves->selectionModel ()->selectedIndexes ().count () > 0);
386 QString firstCurveAfter;
387 for (
int row = m_listCurves->model()->rowCount() - 1; row >= 0; row--) {
390 if (indexCurrent == m_listCurves->selectionModel()->selectedIndexes().last()) {
396 firstCurveAfter = indexCurrent.data().toString();
400 for (
int i = m_listCurves->selectionModel ()->selectedIndexes ().count () - 1; i >= 0; i--) {
402 int row = m_listCurves->selectionModel ()->selectedIndexes ().at (i).row ();
404 m_curveNameList->removeRow (row);
407 if (firstCurveAfter.isEmpty ()) {
410 int numItems = m_listCurves->model()->rowCount();
412 firstCurveAfter = m_listCurves->model()->data (indexLast).toString();
417 selectCurveName(firstCurveAfter);
420void DlgSettingsCurveList::selectCurveName (
const QString &curveWanted)
423 <<
" curve=" << curveWanted.toLatin1().data();
425 for (
int row = 0; row < m_listCurves->model()->rowCount(); row++) {
428 QString curveGot = index.data ().toString ();
430 if (curveWanted == curveGot) {
433 m_listCurves->setCurrentIndex (index);
447void DlgSettingsCurveList::slotDataChanged (
const QModelIndex &topLeft,
448 const QModelIndex &bottomRight,
449 const QVector<int> &roles)
454 QString curveEntries;
455 QTextStream str (&curveEntries);
459 <<
" topLeft=(" << topLeft.row () <<
"," << topLeft.column () <<
")"
460 <<
" bottomRight=(" << bottomRight.row () <<
"," << bottomRight.column () <<
")"
462 <<
" defaultDragOption=" << (m_listCurves->defaultDropAction() == Qt::MoveAction ?
"MoveAction" :
"CopyAction")
463 <<
" curveEntries=(" << curveEntries.toLatin1().data() <<
")";
468void DlgSettingsCurveList::slotNew ()
472 const QString NO_ORIGINAL_CURVE_NAME;
473 const int NO_POINTS = 0;
475 QString curveNameSuggestion = nextCurveName ();
477 int row = newRowFromSelection();
479 insertCurveName (row,
481 NO_ORIGINAL_CURVE_NAME,
484 selectCurveName (curveNameSuggestion);
489void DlgSettingsCurveList::slotRemove ()
494 int numPoints = signed (numPointsForSelectedCurves ());
496 int rtn = QMessageBox::Ok;
500 if (m_listCurves->selectionModel ()->selectedIndexes ().count () == 1) {
501 msg = QString (
"%1 %2 %3")
502 .arg (tr (
"Removing this curve will also remove"))
504 .arg (tr (
"points. Continue?"));
506 msg = QString (
"%1 %2 %3")
507 .arg (tr (
"Removing these curves will also remove"))
509 .arg (tr (
"points. Continue?"));
512 rtn = QMessageBox::warning (
nullptr,
513 tr (
"Curves With Points"),
516 QMessageBox::Cancel);
519 if (rtn == QMessageBox::Ok) {
520 removeSelectedCurves ();
526void DlgSettingsCurveList::slotResetDefault()
530 const QString REMOVE_ALL_SETTINGS_IN_GROUP;
534 int indexOneBased = 1;
536 SettingsForGraph settingsForGraph;
538 while (settings.childGroups().contains (groupName)) {
540 settings.beginGroup (groupName);
541 settings.remove (REMOVE_ALL_SETTINGS_IN_GROUP);
542 settings.endGroup ();
554 <<
" parentValid=" << (parent.isValid() ?
"yes" :
"no")
555 <<
" rowFirst=" << rowFirst
556 <<
" rowLast=" << rowLast;
561void DlgSettingsCurveList::slotSaveDefault()
567 for (
int row = 0; row < m_curveNameList->
rowCount (); row++) {
569 QModelIndex idxCurrent = m_curveNameList->index (row, 0);
571 QString curveNameCurrent = m_curveNameList->data (idxCurrent).toString ();
573 int indexOneBased = row + 1;
578 settings.beginGroup (groupName);
581 settings.endGroup ();
587 QWhatsThis::enterWhatsThisMode();
590void DlgSettingsCurveList::updateControls ()
598 int numSelectedItems = m_listCurves->selectionModel ()->selectedIndexes ().count ();
599 int numItems = m_curveNameList->
rowCount ();
602 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.
#define ENGAUGE_CHECK_PTR(ptr)
Drop in replacement for Q_CHECK_PTR.
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.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.
void insertRow(int row, const QString &curveCurrent, const QString &curveOriginal, unsigned int pointCount)
Create a new entry at the specified row.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
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 createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
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)