diff widgets/ModelDataTableDialog.cpp @ 552:2e8194a30f40 sv-v1.7.1

* Layer data editor window: fix sorting for columns in region model, add Find feature * RDF import: assign names to layers based on event types, if no suitable labels are found in the RDF * Add label to status bar showing the last text that was passed in current layer (so e.g. counting 1, 2, 3, 4 if that's what beats are labelled) * Better layout of text labels for region layers in segmentation mode when they are close together * Give text layer the same method for finding "nearest point" as region and note layers, should improve its editability
author Chris Cannam
date Thu, 22 Oct 2009 15:54:21 +0000
parents 55cdd79606ba
children f4960f8ce798
line wrap: on
line diff
--- a/widgets/ModelDataTableDialog.cpp	Fri Oct 02 13:56:10 2009 +0000
+++ b/widgets/ModelDataTableDialog.cpp	Thu Oct 22 15:54:21 2009 +0000
@@ -23,7 +23,9 @@
 #include "IconLoader.h"
 
 #include <QTableView>
+#include <QLineEdit>
 #include <QGridLayout>
+#include <QLabel>
 #include <QGroupBox>
 #include <QDialogButtonBox>
 #include <QHeaderView>
@@ -102,17 +104,26 @@
     subgrid->setSpacing(0);
     subgrid->setMargin(5);
 
+    subgrid->addWidget(new QLabel(tr("Find:")), 1, 0);
+    subgrid->addWidget(new QLabel(tr(" ")), 1, 1);
+    m_find = new QLineEdit;
+    subgrid->addWidget(m_find, 1, 2);
+    connect(m_find, SIGNAL(textChanged(const QString &)),
+            this, SLOT(searchTextChanged(const QString &)));
+    connect(m_find, SIGNAL(returnPressed()),
+            this, SLOT(searchRepeated()));
+
     m_tableView = new QTableView;
-    subgrid->addWidget(m_tableView);
+    subgrid->addWidget(m_tableView, 0, 0, 1, 3);
 
-//    m_tableView->verticalHeader()->hide();
-//    m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
     m_tableView->setSortingEnabled(true);
     m_tableView->sortByColumn(0, Qt::AscendingOrder);
 
     m_table = new ModelDataTableModel(model);
     m_tableView->setModel(m_table);
 
+    m_tableView->horizontalHeader()->setStretchLastSection(true);
+
     connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
             this, SLOT(viewClicked(const QModelIndex &)));
     connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
@@ -141,8 +152,11 @@
     if (height < 370) {
         if (available.height() > 500) height = 370;
     }
-    if (width < 500) {
-        if (available.width() > 650) width = 500;
+    if (width < 650) {
+        if (available.width() > 750) width = 650;
+        else if (width < 500) {
+            if (available.width() > 650) width = 500;
+        }
     }
 
     resize(width, height);
@@ -170,6 +184,28 @@
 }
 
 void
+ModelDataTableDialog::searchTextChanged(const QString &text)
+{
+    QModelIndex mi = m_table->findText(text);
+    if (mi.isValid()) {
+        makeCurrent(mi.row());
+        m_tableView->selectionModel()->setCurrentIndex
+            (mi, QItemSelectionModel::ClearAndSelect);
+    }
+}
+
+void
+ModelDataTableDialog::searchRepeated()
+{
+    QModelIndex mi = m_table->findText(m_find->text());
+    if (mi.isValid()) {
+        makeCurrent(mi.row());
+        m_tableView->selectionModel()->setCurrentIndex
+            (mi, QItemSelectionModel::ClearAndSelect);
+    }
+}
+
+void
 ModelDataTableDialog::makeCurrent(int row)
 {
     int rh = m_tableView->height() / m_tableView->rowHeight(0);