Coverage Report

Created: 2025-11-24 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WItemSelectionModel.C
Line
Count
Source
1
/*
2
 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3
 *
4
 * See the LICENSE file for terms of use.
5
 */
6
7
#include "Wt/WItemSelectionModel.h"
8
#include "Wt/WAbstractItemModel.h"
9
10
#include <string>
11
12
namespace Wt {
13
14
WItemSelectionModel::WItemSelectionModel()
15
0
  : selectionBehavior_(SelectionBehavior::Rows)
16
0
{ }
17
18
WItemSelectionModel
19
::WItemSelectionModel(const std::shared_ptr<WAbstractItemModel>& model)
20
0
  : model_(model),
21
0
    selectionBehavior_(SelectionBehavior::Rows)
22
0
{ }
23
24
void WItemSelectionModel::setSelectionBehavior(SelectionBehavior behavior)
25
0
{
26
0
  selectionBehavior_ = behavior;
27
0
}
28
29
bool WItemSelectionModel::isSelected(const WModelIndex& index) const
30
0
{
31
0
  if (selectionBehavior_ == SelectionBehavior::Rows) {
32
0
    for (std::set<WModelIndex>::const_iterator it = selection_.begin() ;
33
0
         it != selection_.end(); ++it ) {
34
0
      WModelIndex mi = *it;
35
0
      if (mi.row() == index.row() && mi.parent() == index.parent())
36
0
        return true;
37
0
    }
38
0
    return false;
39
0
  } else {
40
0
    return selection_.find(index) != selection_.end();
41
0
  }
42
0
}
43
44
std::string WItemSelectionModel::mimeType()
45
0
{
46
0
  std::string retval;
47
48
  // Check that all selected mime types are the same
49
50
0
  for (WModelIndexSet::const_iterator i = selection_.begin();
51
0
       i != selection_.end(); ++i) {
52
0
    WModelIndex mi = *i;
53
54
0
    if (!(mi.flags() & ItemFlag::DragEnabled))
55
0
      return std::string();
56
57
0
    cpp17::any mimeTypeData = mi.data(ItemDataRole::MimeType);
58
0
    if (cpp17::any_has_value(mimeTypeData)) {
59
0
      std::string currentMimeType = asString(mimeTypeData).toUTF8();
60
61
0
      if (!currentMimeType.empty()) {
62
0
        if (retval.empty())
63
0
          retval = currentMimeType;
64
0
        else if (currentMimeType != retval)
65
0
          return model_->mimeType();
66
0
      }
67
0
    }
68
0
  }
69
70
0
  if (retval.empty())
71
0
    return selection_.empty() ? std::string() : model_->mimeType();
72
0
  else
73
0
    return retval;
74
0
}
75
76
void WItemSelectionModel::modelLayoutAboutToBeChanged()
77
0
{
78
0
  WModelIndex::encodeAsRawIndexes(selection_);
79
0
}
80
81
void WItemSelectionModel::modelLayoutChanged()
82
0
{
83
0
  selection_ = WModelIndex::decodeFromRawIndexes(selection_);
84
0
}
85
86
}