]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/CategorizedCombo.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / CategorizedCombo.cpp
index d4410cf16896fa57dde76698c3e3332e660f3380..1fd7f35debc155285f0a6853917d3c9987a336a1 100644 (file)
 #include <QStandardItemModel>
 #include <QTextFrame>
 
-using namespace std;
-using namespace lyx;
 using namespace lyx::support;
 
+namespace lyx {
+namespace frontend {
+
 
 class CCItemDelegate : public QItemDelegate {
 public:
@@ -128,13 +129,13 @@ struct CategorizedCombo::Private
 };
 
 
-static QString category(QAbstractItemModel const & model, int row)
+static QString categoryCC(QAbstractItemModel const & model, int row)
 {
        return model.data(model.index(row, 2), Qt::DisplayRole).toString();
 }
 
 
-static int headerHeight(QStyleOptionViewItem const & opt)
+static int headerHeightCC(QStyleOptionViewItem const & opt)
 {
        return opt.fontMetrics.height();
 }
@@ -148,10 +149,10 @@ void CCItemDelegate::paint(QPainter * painter, QStyleOptionViewItem const & opti
        // default background
        painter->fillRect(opt.rect, opt.palette.color(QPalette::Base));
 
-       QString cat = category(*index.model(), index.row());
+       QString cat = categoryCC(*index.model(), index.row());
 
        // not the same as in the previous line?
-       if (index.row() == 0 || cat != category(*index.model(), index.row() - 1)) {
+       if (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1)) {
                painter->save();
 
                // draw unselected background
@@ -162,10 +163,10 @@ void CCItemDelegate::paint(QPainter * painter, QStyleOptionViewItem const & opti
 
                // draw category header
                drawCategoryHeader(painter, opt, 
-                       category(*index.model(), index.row()));
+                       categoryCC(*index.model(), index.row()));
 
                // move rect down below header
-               opt.rect.setTop(opt.rect.top() + headerHeight(opt));
+               opt.rect.setTop(opt.rect.top() + headerHeightCC(opt));
 
                painter->restore();
        }
@@ -216,9 +217,9 @@ QSize CCItemDelegate::sizeHint(QStyleOptionViewItem const & opt,
        /// So we tweak this value accordingly. It's not nice, but the
        /// only possible way it seems.
        // Add space for the category headers here
-       QString cat = category(*index.model(), index.row());
-       if (index.row() == 0 || cat != category(*index.model(), index.row() - 1)) {
-               size.setHeight(size.height() + headerHeight(opt));
+       QString cat = categoryCC(*index.model(), index.row());
+       if (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1)) {
+               size.setHeight(size.height() + headerHeightCC(opt));
        }
 
        return size;
@@ -289,7 +290,7 @@ QString CCItemDelegate::underlineFilter(QString const & s) const
 }
 
 
-static QString charFilterRegExp(QString const & filter)
+static QString charFilterRegExpCC(QString const & filter)
 {
        QString re;
        for (int i = 0; i < filter.length(); ++i) {
@@ -314,7 +315,7 @@ void CategorizedCombo::Private::setFilter(QString const & s)
                lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
 
        filter_ = s;
-       filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+       filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
        countCategories();
        
        // restore old selection
@@ -493,7 +494,9 @@ void CategorizedCombo::addItemSort(QString const & item, QString const & guiname
                                   bool sorted, bool sortedByCat, bool sortCats,
                                   bool available)
 {
-       QString titem = available ? guiname : qt_("Unavailable: %1").arg(guiname);
+       QString titem = available ? guiname
+                                 : toqstr(bformat(_("Unavailable: %1$s"),
+                                                  qstring_to_ucs4(guiname)));
        bool const uncategorized = category.isEmpty();
        QString qcat = uncategorized ? qt_("Uncategorized") : category;
 
@@ -554,7 +557,8 @@ void CategorizedCombo::addItemSort(QString const & item, QString const & guiname
 
 QString CategorizedCombo::getData(int row) const
 {
-       return d->model_->data(d->model_->index(row, 1), Qt::DisplayRole).toString();
+       int srow = d->filterModel_->mapToSource(d->filterModel_->index(row, 1)).row();
+       return d->model_->data(d->model_->index(srow, 1), Qt::DisplayRole).toString();
 }
 
 
@@ -581,5 +585,8 @@ QString const & CategorizedCombo::filter() const
        return d->filter_;
 }
 
+}  // namespace frontend
+}  // namespace lyx
+
 
 #include "moc_CategorizedCombo.cpp"