a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp
...
...
272
    g_hiliter.set_inputhtml(false);
272
    g_hiliter.set_inputhtml(false);
273
}
273
}
274
274
275
int RecollModel::rowCount(const QModelIndex&) const
275
int RecollModel::rowCount(const QModelIndex&) const
276
{
276
{
277
    LOGDEB2("RecollModel::rowCount\n" );
277
    LOGDEB2("RecollModel::rowCount\n");
278
    if (!m_source)
278
    if (!m_source)
279
    return 0;
279
    return 0;
280
    return m_source->getResCnt();
280
    return m_source->getResCnt();
281
}
281
}
282
282
283
int RecollModel::columnCount(const QModelIndex&) const
283
int RecollModel::columnCount(const QModelIndex&) const
284
{
284
{
285
    LOGDEB2("RecollModel::columnCount\n" );
285
    LOGDEB2("RecollModel::columnCount\n");
286
    return m_fields.size();
286
    return m_fields.size();
287
}
287
}
288
288
289
void RecollModel::readDocSource()
289
void RecollModel::readDocSource()
290
{
290
{
291
    LOGDEB("RecollModel::readDocSource()\n" );
291
    LOGDEB("RecollModel::readDocSource()\n");
292
    beginResetModel();
292
    beginResetModel();
293
    endResetModel();
293
    endResetModel();
294
}
294
}
295
295
296
void RecollModel::setDocSource(std::shared_ptr<DocSequence> nsource)
296
void RecollModel::setDocSource(std::shared_ptr<DocSequence> nsource)
297
{
297
{
298
    LOGDEB("RecollModel::setDocSource\n" );
298
    LOGDEB("RecollModel::setDocSource\n");
299
    if (!nsource) {
299
    if (!nsource) {
300
    m_source = std::shared_ptr<DocSequence>();
300
    m_source = std::shared_ptr<DocSequence>();
301
    } else {
301
    } else {
302
    m_source = std::shared_ptr<DocSequence>(new DocSource(theconfig, nsource));
302
    m_source = std::shared_ptr<DocSequence>(new DocSource(theconfig, nsource));
303
    m_hdata.clear();
303
    m_hdata.clear();
...
...
318
    }
318
    }
319
}
319
}
320
320
321
void RecollModel::addColumn(int col, const string& field)
321
void RecollModel::addColumn(int col, const string& field)
322
{
322
{
323
    LOGDEB("AddColumn: col "  << (col) << " fld ["  << (field) << "]\n" );
323
    LOGDEB("AddColumn: col " << col << " fld ["  << field << "]\n");
324
    if (col >= 0 && col < int(m_fields.size())) {
324
    if (col >= 0 && col < int(m_fields.size())) {
325
    col++;
325
    col++;
326
    vector<string>::iterator it = m_fields.begin();
326
    vector<string>::iterator it = m_fields.begin();
327
    vector<FieldGetter*>::iterator it1 = m_getters.begin();
327
    vector<FieldGetter*>::iterator it1 = m_getters.begin();
328
    if (col) {
328
    if (col) {
...
...
336
}
336
}
337
337
338
QVariant RecollModel::headerData(int idx, Qt::Orientation orientation, 
338
QVariant RecollModel::headerData(int idx, Qt::Orientation orientation, 
339
                 int role) const
339
                 int role) const
340
{
340
{
341
    LOGDEB2("RecollModel::headerData: idx "  << (idx) << " orientation "  << (orientation == Qt::Vertical ? "vertical":"horizontal") << " role "  << (role) << "\n" );
341
    LOGDEB2("RecollModel::headerData: idx " << idx << " orientation " <<
342
            (orientation == Qt::Vertical ? "vertical":"horizontal") <<
343
            " role " << role << "\n");
342
    if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
344
    if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
343
        return idx;
345
        return idx;
344
    }
346
    }
345
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole &&
347
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole &&
346
    idx < int(m_fields.size())) {
348
    idx < int(m_fields.size())) {
...
...
354
    return QVariant();
356
    return QVariant();
355
}
357
}
356
358
357
QVariant RecollModel::data(const QModelIndex& index, int role) const
359
QVariant RecollModel::data(const QModelIndex& index, int role) const
358
{
360
{
359
    LOGDEB2("RecollModel::data: row "  << (index.row()) << " col "  << (index.column()) << " role "  << (role) << "\n" );
361
    LOGDEB2("RecollModel::data: row " << index.row() << " col " <<
362
            index.column() << " role " << role << "\n");
360
    if (!m_source || role != Qt::DisplayRole || !index.isValid() ||
363
    if (!m_source || role != Qt::DisplayRole || !index.isValid() ||
361
    index.column() >= int(m_fields.size())) {
364
    index.column() >= int(m_fields.size())) {
362
    return QVariant();
365
    return QVariant();
363
    }
366
    }
364
367
...
...
407
}
410
}
408
411
409
// This gets called when the column headers are clicked
412
// This gets called when the column headers are clicked
410
void RecollModel::sort(int column, Qt::SortOrder order)
413
void RecollModel::sort(int column, Qt::SortOrder order)
411
{
414
{
412
    if (m_ignoreSort)
415
    if (m_ignoreSort) {
413
    return;
416
    return;
417
    }
414
    LOGDEB("RecollModel::sort("  << (column) << ", "  << (int(order)) << ")\n" );
418
    LOGDEB("RecollModel::sort(" << column << ", " << order << ")\n");
415
    
419
    
416
    DocSeqSortSpec spec;
420
    DocSeqSortSpec spec;
417
    if (column >= 0 && column < int(m_fields.size())) {
421
    if (column >= 0 && column < int(m_fields.size())) {
418
    spec.field = m_fields[column];
422
    spec.field = m_fields[column];
419
    if (!stringlowercmp("date", spec.field) || 
423
    if (!stringlowercmp("date", spec.field) || 
420
        !stringlowercmp("datetime", spec.field))
424
        !stringlowercmp("datetime", spec.field))
421
        spec.field = "mtime";
425
        spec.field = "mtime";
422
    spec.desc = order == Qt::AscendingOrder ? false : true;
426
    spec.desc = order == Qt::AscendingOrder ? false : true;
423
    } 
427
    }
424
    emit sortDataChanged(spec);
428
    emit sortDataChanged(spec);
425
}
429
}
426
430
427
/////////////////////////// 
431
/////////////////////////// 
428
// ResTable panel methods
432
// ResTable panel methods
...
...
522
                      ROWHEIGHTPAD);
526
                      ROWHEIGHTPAD);
523
    }
527
    }
524
528
525
    QKeySequence seq("Esc");
529
    QKeySequence seq("Esc");
526
    QShortcut *sc = new QShortcut(seq, this);
530
    QShortcut *sc = new QShortcut(seq, this);
527
    connect(sc, SIGNAL (activated()), 
531
    connect(sc, SIGNAL(activated()), 
528
        tableView->selectionModel(), SLOT (clear()));
532
        tableView->selectionModel(), SLOT(clear()));
529
    connect(tableView->selectionModel(), 
533
    connect(tableView->selectionModel(), 
530
        SIGNAL(currentChanged(const QModelIndex&, const QModelIndex &)),
534
        SIGNAL(currentChanged(const QModelIndex&, const QModelIndex &)),
531
        this, SLOT(onTableView_currentChanged(const QModelIndex&)));
535
        this, SLOT(onTableView_currentChanged(const QModelIndex&)));
532
    connect(tableView, SIGNAL(doubleClicked(const QModelIndex&)), 
536
    connect(tableView, SIGNAL(doubleClicked(const QModelIndex&)), 
533
            this, SLOT(onDoubleClick(const QModelIndex&)));
537
            this, SLOT(onDoubleClick(const QModelIndex&)));
...
...
591
    return modelIndex.row();
595
    return modelIndex.row();
592
}
596
}
593
597
594
void ResTable::makeRowVisible(int row)
598
void ResTable::makeRowVisible(int row)
595
{
599
{
596
    LOGDEB("ResTable::showRow("  << (row) << ")\n" );
600
    LOGDEB("ResTable::showRow(" << row << ")\n");
597
    QModelIndex modelIndex = m_model->index(row, 0);
601
    QModelIndex modelIndex = m_model->index(row, 0);
598
    tableView->scrollTo(modelIndex, QAbstractItemView::PositionAtTop);
602
    tableView->scrollTo(modelIndex, QAbstractItemView::PositionAtTop);
599
    tableView->selectionModel()->clear();
603
    tableView->selectionModel()->clear();
600
    m_detail->clear();
604
    m_detail->clear();
601
    m_detaildocnum = -1;
605
    m_detaildocnum = -1;
...
...
610
    settings.setValue("resTableSplitterSizes", splitter->saveState());
614
    settings.setValue("resTableSplitterSizes", splitter->saveState());
611
615
612
    QHeaderView *header = tableView->horizontalHeader();
616
    QHeaderView *header = tableView->horizontalHeader();
613
    const vector<string>& vf = m_model->getFields();
617
    const vector<string>& vf = m_model->getFields();
614
    if (!header) {
618
    if (!header) {
615
    LOGERR("ResTable::saveColState: no table header ??\n" );
619
    LOGERR("ResTable::saveColState: no table header ??\n");
616
    return;
620
    return;
617
    }
621
    }
618
622
619
    // Remember the current column order. Walk in visual order and
623
    // Remember the current column order. Walk in visual order and
620
    // create new list
624
    // create new list
621
    QStringList newfields;
625
    QStringList newfields;
622
    vector<int> newwidths;
626
    vector<int> newwidths;
623
    for (int vi = 0; vi < header->count(); vi++) {
627
    for (int vi = 0; vi < header->count(); vi++) {
624
    int li = header->logicalIndex(vi);
628
    int li = header->logicalIndex(vi);
625
    if (li < 0 || li >= int(vf.size())) {
629
    if (li < 0 || li >= int(vf.size())) {
626
        LOGERR("saveColState: logical index beyond list size!\n" );
630
        LOGERR("saveColState: logical index beyond list size!\n");
627
        continue;
631
        continue;
628
    }
632
    }
629
    newfields.push_back(QString::fromUtf8(vf[li].c_str()));
633
    newfields.push_back(QString::fromUtf8(vf[li].c_str()));
630
    newwidths.push_back(header->sectionSize(li));
634
    newwidths.push_back(header->sectionSize(li));
631
    }
635
    }
...
...
633
    prefs.restableColWidths = newwidths;
637
    prefs.restableColWidths = newwidths;
634
}
638
}
635
639
636
void ResTable::onTableView_currentChanged(const QModelIndex& index)
640
void ResTable::onTableView_currentChanged(const QModelIndex& index)
637
{
641
{
638
    LOGDEB2("ResTable::onTableView_currentChanged("  << (index.row()) << ", "  << (index.column()) << ")\n" );
642
    LOGDEB2("ResTable::onTableView_currentChanged(" << index.row() << ", " <<
643
            index.column() << ")\n");
639
644
640
    if (!m_model || !m_model->getDocSource())
645
    if (!m_model || !m_model->getDocSource())
641
    return;
646
    return;
642
    Rcl::Doc doc;
647
    Rcl::Doc doc;
643
    if (m_model->getDocSource()->getDoc(index.row(), doc)) {
648
    if (m_model->getDocSource()->getDoc(index.row(), doc)) {
...
...
651
    }
656
    }
652
}
657
}
653
658
654
void ResTable::on_tableView_entered(const QModelIndex& index)
659
void ResTable::on_tableView_entered(const QModelIndex& index)
655
{
660
{
656
    LOGDEB2("ResTable::on_tableView_entered("  << (index.row()) << ", "  << (index.column()) << ")\n" );
661
    LOGDEB2("ResTable::on_tableView_entered(" << index.row() << ", "  <<
662
            index.column() << ")\n");
657
    if (!tableView->selectionModel()->hasSelection())
663
    if (!tableView->selectionModel()->hasSelection())
658
    onTableView_currentChanged(index);
664
    onTableView_currentChanged(index);
659
}
665
}
660
666
661
void ResTable::takeFocus()
667
void ResTable::takeFocus()
662
{
668
{
663
//    LOGDEB("resTable: take focus\n" );
669
//    LOGDEB("resTable: take focus\n");
664
    tableView->setFocus(Qt::ShortcutFocusReason);
670
    tableView->setFocus(Qt::ShortcutFocusReason);
665
}
671
}
666
672
667
void ResTable::setDocSource(std::shared_ptr<DocSequence> nsource)
673
void ResTable::setDocSource(std::shared_ptr<DocSequence> nsource)
668
{
674
{
669
    LOGDEB("ResTable::setDocSource\n" );
675
    LOGDEB("ResTable::setDocSource\n");
670
    if (m_model)
676
    if (m_model)
671
    m_model->setDocSource(nsource);
677
    m_model->setDocSource(nsource);
672
    if (m_pager)
678
    if (m_pager)
673
    m_pager->setDocSource(nsource, 0);
679
    m_pager->setDocSource(nsource, 0);
674
    if (m_detail)
680
    if (m_detail)
...
...
676
    m_detaildocnum = -1;
682
    m_detaildocnum = -1;
677
}
683
}
678
684
679
void ResTable::resetSource()
685
void ResTable::resetSource()
680
{
686
{
681
    LOGDEB("ResTable::resetSource\n" );
687
    LOGDEB("ResTable::resetSource\n");
682
    setDocSource(std::shared_ptr<DocSequence>());
688
    setDocSource(std::shared_ptr<DocSequence>());
683
}
689
}
684
690
685
void ResTable::saveAsCSV()
691
void ResTable::saveAsCSV()
686
{
692
{
687
    LOGDEB("ResTable::saveAsCSV\n" );
693
    LOGDEB("ResTable::saveAsCSV\n");
688
    if (!m_model)
694
    if (!m_model)
689
    return;
695
    return;
690
    QString s = 
696
    QString s = 
691
    QFileDialog::getSaveFileName(this, //parent
697
    QFileDialog::getSaveFileName(this, //parent
692
                     tr("Save table to CSV file"),
698
                     tr("Save table to CSV file"),
...
...
706
}
712
}
707
713
708
// This is called when the sort order is changed from another widget
714
// This is called when the sort order is changed from another widget
709
void ResTable::onSortDataChanged(DocSeqSortSpec spec)
715
void ResTable::onSortDataChanged(DocSeqSortSpec spec)
710
{
716
{
711
    LOGDEB("ResTable::onSortDataChanged: ["  << (spec.field) << "] desc "  << (int(spec.desc)) << "\n" );
717
    LOGDEB("ResTable::onSortDataChanged: [" << spec.field << "] desc " <<
718
           spec.desc << "\n");
712
    QHeaderView *header = tableView->horizontalHeader();
719
    QHeaderView *header = tableView->horizontalHeader();
713
    if (!header || !m_model)
720
    if (!header || !m_model)
714
    return;
721
    return;
715
722
716
    // Check if the specified field actually matches one of columns
723
    // Check if the specified field actually matches one of columns
...
...
730
    m_model->setIgnoreSort(false);
737
    m_model->setIgnoreSort(false);
731
}
738
}
732
739
733
void ResTable::resetSort()
740
void ResTable::resetSort()
734
{
741
{
735
    LOGDEB("ResTable::resetSort()\n" );
742
    LOGDEB("ResTable::resetSort()\n");
736
    QHeaderView *header = tableView->horizontalHeader();
743
    QHeaderView *header = tableView->horizontalHeader();
737
    if (header)
744
    if (header)
738
    header->setSortIndicator(-1, Qt::AscendingOrder); 
745
    header->setSortIndicator(-1, Qt::AscendingOrder); 
739
    // the model's sort slot is not called by qt in this case (qt 4.7)
746
    // the model's sort slot is not called by qt in this case (qt 4.7)
740
    if (m_model)
747
    if (m_model)
741
    m_model->sort(-1, Qt::AscendingOrder);
748
    m_model->sort(-1, Qt::AscendingOrder);
742
}
749
}
743
750
744
void ResTable::readDocSource(bool resetPos)
751
void ResTable::readDocSource(bool resetPos)
745
{
752
{
746
    LOGDEB("ResTable::readDocSource("  << (int(resetPos)) << ")\n" );
753
    LOGDEB("ResTable::readDocSource("  << resetPos << ")\n");
747
    if (resetPos)
754
    if (resetPos)
748
    tableView->verticalScrollBar()->setSliderPosition(0);
755
    tableView->verticalScrollBar()->setSliderPosition(0);
749
756
750
    m_model->readDocSource();
757
    m_model->readDocSource();
751
    m_detail->clear();
758
    m_detail->clear();
...
...
757
    if (m_detaildocnum < 0) {
764
    if (m_detaildocnum < 0) {
758
    return;
765
    return;
759
    }
766
    }
760
    QString s = url.toString();
767
    QString s = url.toString();
761
    const char *ascurl = s.toUtf8();
768
    const char *ascurl = s.toUtf8();
762
    LOGDEB("ResTable::linkWasClicked: ["  << (ascurl) << "]\n" );
769
    LOGDEB("ResTable::linkWasClicked: [" << ascurl << "]\n");
763
770
764
    int i = atoi(ascurl+1) -1;
771
    int i = atoi(ascurl+1) -1;
765
    int what = ascurl[0];
772
    int what = ascurl[0];
766
    switch (what) {
773
    switch (what) {
767
    // Open abstract/snippets window
774
    // Open abstract/snippets window
...
...
817
        }
824
        }
818
    }
825
    }
819
    break;
826
    break;
820
827
821
    default: 
828
    default: 
822
    LOGERR("ResTable::linkWasClicked: bad link ["  << (ascurl) << "]\n" );
829
    LOGERR("ResTable::linkWasClicked: bad link [" << ascurl << "]\n");
823
    break;// ?? 
830
    break;// ?? 
824
    }
831
    }
825
}
832
}
826
833
827
void ResTable::onDoubleClick(const QModelIndex& index)
834
void ResTable::onDoubleClick(const QModelIndex& index)
...
...
840
    }
847
    }
841
}
848
}
842
849
843
void ResTable::createPopupMenu(const QPoint& pos)
850
void ResTable::createPopupMenu(const QPoint& pos)
844
{
851
{
845
    LOGDEB("ResTable::createPopupMenu: m_detaildocnum "  << (m_detaildocnum) << "\n" );
852
    LOGDEB("ResTable::createPopupMenu: m_detaildocnum " << m_detaildocnum <<
853
           "\n");
846
    if (m_detaildocnum >= 0 && m_model) {
854
    if (m_detaildocnum >= 0 && m_model) {
847
    int opts = m_ismainres? ResultPopup::isMain : 0;
855
    int opts = m_ismainres? ResultPopup::isMain : 0;
848
    
856
    
849
    int selsz = tableView->selectionModel()->selectedRows().size();
857
    int selsz = tableView->selectionModel()->selectedRows().size();
850
858
...
...
971
    emit showSubDocs(m_detaildoc);
979
    emit showSubDocs(m_detaildoc);
972
}
980
}
973
981
974
void ResTable::createHeaderPopupMenu(const QPoint& pos)
982
void ResTable::createHeaderPopupMenu(const QPoint& pos)
975
{
983
{
976
    LOGDEB("ResTable::createHeaderPopupMenu("  << (pos.x()) << ", "  << (pos.y()) << ")\n" );
984
    LOGDEB("ResTable::createHeaderPopupMenu(" << pos.x() << ", " <<
985
           pos.y() << ")\n");
977
    QHeaderView *header = tableView->horizontalHeader();
986
    QHeaderView *header = tableView->horizontalHeader();
978
    if (!header || !m_model)
987
    if (!header || !m_model)
979
    return;
988
    return;
980
989
981
    m_popcolumn = header->logicalIndexAt(pos);
990
    m_popcolumn = header->logicalIndexAt(pos);
...
...
1017
void ResTable::addColumn()
1026
void ResTable::addColumn()
1018
{
1027
{
1019
    if (!m_model)
1028
    if (!m_model)
1020
    return;
1029
    return;
1021
    QAction *action = (QAction *)sender();
1030
    QAction *action = (QAction *)sender();
1022
    LOGDEB("addColumn: text "  << (qs2utf8s(action->text())) << ", data "  << (qs2utf8s(action->data().toString())) << "\n" );
1031
    LOGDEB("addColumn: text " << qs2utf8s(action->text()) << ", data " <<
1032
           qs2utf8s(action->data().toString()) << "\n");
1023
    m_model->addColumn(m_popcolumn, qs2utf8s(action->data().toString()));
1033
    m_model->addColumn(m_popcolumn, qs2utf8s(action->data().toString()));
1024
}
1034
}
1025
1035