changeset 1286:e327bbf4bf57 plugin-path-config

Up/down
author Chris Cannam
date Tue, 15 May 2018 11:18:07 +0100
parents abd52bd8d435
children 2dd7f764c3a6
files widgets/PluginPathConfigurator.cpp widgets/PluginPathConfigurator.h
diffstat 2 files changed, 81 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/PluginPathConfigurator.cpp	Fri May 11 16:59:14 2018 +0100
+++ b/widgets/PluginPathConfigurator.cpp	Tue May 15 11:18:07 2018 +0100
@@ -21,12 +21,12 @@
 #include "WidgetScale.h"
 
 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
-    QFrame(parent)
+    QFrame(parent),
+    m_innerFrame(0)
 {
     setFrameStyle(StyledPanel | Sunken);
     m_layout = new QGridLayout;
     setLayout(m_layout);
-    populate();
 }
 
 PluginPathConfigurator::~PluginPathConfigurator()
@@ -44,9 +44,16 @@
 void
 PluginPathConfigurator::populate()
 {
-    QLabel *header = new QLabel;
+    delete m_innerFrame;
+    m_innerFrame = new QWidget;
+    m_layout->addWidget(m_innerFrame, 0, 0);
+
+    QGridLayout *innerLayout = new QGridLayout;
+    m_innerFrame->setLayout(innerLayout);
+    
+    QLabel *header = new QLabel(m_innerFrame);
     header->setText(QString("<b>%1</b>").arg(tr("Location")));
-    m_layout->addWidget(header, 0, 3);
+    innerLayout->addWidget(header, 0, 3);
     
     for (int i = 0; i < m_path.size(); ++i) {
 
@@ -55,52 +62,103 @@
         QString dir = m_path[i];
 
         if (i > 0) {
-            QPushButton *up = new QPushButton;
+            QPushButton *up = new QPushButton(m_innerFrame);
+            up->setObjectName(QString("%1").arg(i));
             up->setIcon(IconLoader().load("up"));
             up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
             connect(up, SIGNAL(clicked()), this, SLOT(upClicked()));
-            m_layout->addWidget(up, row, col);
+            innerLayout->addWidget(up, row, col);
         }
         ++col;
 
         if (i + 1 < m_path.size()) {
-            QPushButton *down = new QPushButton;
+            QPushButton *down = new QPushButton(m_innerFrame);
+            down->setObjectName(QString("%1").arg(i));
             down->setIcon(IconLoader().load("down"));
             down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
             connect(down, SIGNAL(clicked()), this, SLOT(downClicked()));
-            m_layout->addWidget(down, row, col);
+            innerLayout->addWidget(down, row, col);
         }
         ++col;
 
-        QPushButton *del = new QPushButton;
+        QPushButton *del = new QPushButton(m_innerFrame);
+        del->setObjectName(QString("%1").arg(i));
         del->setIcon(IconLoader().load("datadelete"));
         del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
         connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked()));
-        m_layout->addWidget(del, row, col);
+        innerLayout->addWidget(del, row, col);
         ++col;
 
-        QLabel *dirLabel = new QLabel;
+        QLabel *dirLabel = new QLabel(m_innerFrame);
+        dirLabel->setObjectName(QString("%1").arg(i));
         dirLabel->setText(dir);
-        m_layout->addWidget(dirLabel, row, col);
-        m_layout->setColumnStretch(col, 10);
+        innerLayout->addWidget(dirLabel, row, col);
+        innerLayout->setColumnStretch(col, 10);
         ++col;
-    }        
+    }
 }
 
 void
 PluginPathConfigurator::upClicked()
 {
-    //!!!
+    bool ok = false;
+    int n = sender()->objectName().toInt(&ok);
+    if (!ok) {
+        SVCERR << "upClicked: unable to find index" << endl;
+        return;
+    }
+    QStringList newPath;
+    for (int i = 0; i < m_path.size(); ++i) {
+        if (i + 1 == n) {
+            newPath.push_back(m_path[i+1]);
+            newPath.push_back(m_path[i]);
+            ++i;
+        } else {
+            newPath.push_back(m_path[i]);
+        }
+    }
+    m_path = newPath;
+    populate();
 }
 
 void
 PluginPathConfigurator::downClicked()
 {
-    //!!!!
+    bool ok = false;
+    int n = sender()->objectName().toInt(&ok);
+    if (!ok) {
+        SVCERR << "downClicked: unable to find index" << endl;
+        return;
+    }
+    QStringList newPath;
+    for (int i = 0; i < m_path.size(); ++i) {
+        if (i == n) {
+            newPath.push_back(m_path[i+1]);
+            newPath.push_back(m_path[i]);
+            ++i;
+        } else {
+            newPath.push_back(m_path[i]);
+        }
+    }
+    m_path = newPath;
+    populate();
 }
 
 void
 PluginPathConfigurator::deleteClicked()
 {
-    //!!!
+    bool ok = false;
+    int n = sender()->objectName().toInt(&ok);
+    if (!ok) {
+        SVCERR << "deleteClicked: unable to find index" << endl;
+        return;
+    }
+    QStringList newPath;
+    for (int i = 0; i < m_path.size(); ++i) {
+        if (i != n) {
+            newPath.push_back(m_path[i]);
+        }
+    }
+    m_path = newPath;
+    populate();
 }
--- a/widgets/PluginPathConfigurator.h	Fri May 11 16:59:14 2018 +0100
+++ b/widgets/PluginPathConfigurator.h	Tue May 15 11:18:07 2018 +0100
@@ -19,6 +19,9 @@
 #include <QGridLayout>
 #include <QStringList>
 
+class QLabel;
+class QWidget;
+
 class PluginPathConfigurator : public QFrame
 {
     Q_OBJECT
@@ -43,9 +46,11 @@
 
     QStringList m_path;
     QString m_var;
+
+    QWidget *m_innerFrame;
+    std::vector<QLabel *> m_labels;
     
     void populate();
-    
 };
 
 #endif