[Kst] branches/work/kst/portto4/kst/src/widgets

Joshua Netterfield drmrshdw at gmail.com
Fri Aug 19 22:48:57 UTC 2011


SVN commit 1248139 by joshuanetterfield:

Adds support for wildcards in categorical completion and keeps completion table width fixed. Should have commited a few days ago, but forgot.


 M  +42 -7     cclineedit.cpp  
 M  +2 -2      cclineedit.h  
 M  +1 -1      cclineedit_p.h  


--- branches/work/kst/portto4/kst/src/widgets/cclineedit.cpp #1248138:1248139
@@ -152,6 +152,14 @@
 void CategoricalCompleter::verifyPrefix()
 {
     QString search=completionPrefix();
+    QString altsearch=search;
+    QStringList altlist;
+    if(search.contains("*")) {
+        search.remove(search.indexOf('*'),99999);
+        altsearch.remove(0,altsearch.indexOf('*')+1);
+        altlist=altsearch.split("*");
+        setCompletionPrefix(search);
+    }
 
     for(int i=_data.size()-1;i>=0;i--) {
         if(!_data[i].prefix().size()||!search.indexOf(_data[i].prefix())) {
@@ -174,11 +182,12 @@
                 }
             }
 
-            if(_currentSubset!=&_data[i]) {
-                setModel(new QStringListModel(join(_data[i],_data[i].prefix())));
+            if(_currentSubset!=&_data[i]||search!=altsearch) {
+                setModel(new QStringListModel(join(_data[i],_data[i].prefix(),(search==altsearch)?QStringList():altlist,search.size())));
                 _tableView->setData(&_data[i],_data[i].prefix());
                 complete();
                 _currentSubset=&_data[i];
+                setCompletionPrefix(search);
             }
             break;
         }
@@ -190,17 +199,26 @@
     //_tableView is child
 }
 
-QStringList CategoricalCompleter::join(CompletionCase& l,QString prefix)
+QStringList CategoricalCompleter::join(CompletionCase& l,QString prefix,QStringList searchpattern,int complength)
 {
     QStringList ret;
     for(int i=0;i<l.size();i++) {
         ret<<l[i];
     }
-    if(prefix.size()) {
+    if(prefix.size()||searchpattern.size()) {
         for(int i=0;i<ret.size();i++) {
             ret[i].prepend(prefix);
+            int lastindex=prefix.size()+complength;
+            for(int j=0;j<searchpattern.size();j++) {
+                if(ret[i].indexOf(searchpattern[j],lastindex,Qt::CaseInsensitive)==-1) {
+                    ret.takeAt(i);
+                    i-=1;
+                    break;
         }
+                lastindex=ret[i].indexOf(searchpattern[j],lastindex)+searchpattern.size();
     }
+        }
+    }
     return ret;
 }
 
@@ -364,6 +382,16 @@
     QLineEdit::mousePressEvent(ev);
 }
 
+void CCLineEdit::ChangeCurrentPrefix(QString x)
+{
+    emit currentPrefixChanged(x);
+}
+
+void CCTextEdit::ChangeCurrentPrefix(QString x)
+{
+    emit currentPrefixChanged(x);
+}
+
 void CCLineEdit::init(QList<CompletionCase> data)
 {
     delete _cc;
@@ -579,6 +607,10 @@
     ScalarList scalarList = _store->getObjects<Scalar>();
     VectorList vectorList = _store->getObjects<Vector>();
 
+    if(_cc&&_cc->_tableView) {
+        _cc->_tableView->setFixedWidth(_cc->_tableView->width());
+    }
+
     ScalarList::ConstIterator scalarIt = scalarList.begin();
     for (; scalarIt != scalarList.end(); ++scalarIt) {
         ScalarPtr scalar = (*scalarIt);
@@ -617,6 +649,10 @@
     _svData->push_back(CompletionCase("["));
     _svData->back().push_back(Category("Scalars"));
 
+    if(_cc&&_cc->_tableView) {
+        _cc->_tableView->setFixedWidth(_cc->_tableView->width());
+    }
+
     ScalarList scalarList = _store->getObjects<Scalar>();
     StringList stringList = _store->getObjects<String>();
 
@@ -921,6 +957,7 @@
     setSelectionMode(QAbstractItemView::SingleSelection);
     setSelectionBehavior(QAbstractItemView::SelectItems);
     setMinimumHeight(150);
+    setFixedWidth(width());
     verticalHeader()->hide();
 }
 
@@ -1039,11 +1076,9 @@
 void CCTableView::showEvent(QShowEvent *)
 {
     //    resizeColumnsToContents();
-    int bestWidth=qMax(width(),(int)((horizontalHeader()->length()+verticalScrollBar()->width())));
+//    int bestWidth=qMax(width(),(int)((horizontalHeader()->length()+verticalScrollBar()->width())));
     horizontalHeader()->setResizeMode(QHeaderView::Interactive);
     horizontalHeader()->setStretchLastSection(1);
-    setMinimumWidth(bestWidth);
-    setMaximumWidth(bestWidth);
 }
 
 void CCTableView::resizeEvent(QResizeEvent*ev)
--- branches/work/kst/portto4/kst/src/widgets/cclineedit.h #1248138:1248139
@@ -85,7 +85,7 @@
     virtual void SetCursorPosition(int x){setCursorPosition(x);}
     virtual void NewPrefix(QString x){emit currentPrefixChanged(x);}
     virtual void SetCompleter(QCompleter*c) {setCompleter(c);}
-    virtual void ChangeCurrentPrefix(QString x){emit currentPrefixChanged(x);}
+    virtual void ChangeCurrentPrefix(QString x);
 
 public:
     friend class CCTableView;
@@ -147,7 +147,7 @@
     virtual void SetCursorPosition(int x){QTextCursor tc=textCursor();tc.setPosition(x);setTextCursor(tc);}
     virtual void NewPrefix(QString x){emit currentPrefixChanged(x);}
     virtual void SetCompleter(QCompleter*) {}
-    virtual void ChangeCurrentPrefix(QString x){emit currentPrefixChanged(x);}
+    virtual void ChangeCurrentPrefix(QString x);
 public:
     friend class CCTableView;
     CCTextEdit(QWidget*p=0);
--- branches/work/kst/portto4/kst/src/widgets/cclineedit_p.h #1248138:1248139
@@ -53,7 +53,7 @@
     bool eventFilter(QObject *o, QEvent *e);
     //  QStringList splitPath(const QString &path) const;
     //  QString pathFromIndex(const QModelIndex &index) const;
-    static QStringList join(CompletionCase&,QString prefix="");
+    static QStringList join(CompletionCase&,QString prefix="",QStringList searchpattern=QStringList(),int complength=0);
     static QStringList getDefault(QList<CompletionCase>&);
 public slots:
     void verifyPrefix();


More information about the Kst mailing list