Модель - представление - контроллер в QT

Вы должны добавить скобки для вызова метода FirstOrDefault

   var frenchvoice = InstalledVoices.All
       .Where(voice => voice.Language.Equals("fr-FR") && 
              voice.Gender == VoiceGender.Female)
       .FirstOrDefault();

И, в то время как ваш код работает также с использованием & amp; оператор, правильный для использования в логическом условии: &&

Кстати, FirstOrDefault принимает ту же лямбду, что и для Where, чтобы вы могли сократить свой код до более простого и, возможно, более быстрого

   var frenchvoice = InstalledVoices.All
       .FirstOrDefault(voice => voice.Language.Equals("fr-FR") && 
                                voice.Gender == VoiceGender.Female);
12
задан Cœur 30 April 2017 в 05:44
поделиться

1 ответ

AbstractItemModel QAbstractItemView QAbstractItemDelegate

Are from the "Mode/View framework"
This is a very powerful framework for the data part of your application, here is a presentation of the framework.

QAbstractItemModel

Is the base class for the model of the MVC. Has a global interface for accessing and altering the data and takes care of the Observable part.

QAbstractItemView

Is the base class for the view of the MVC. Has aglobal interface for the view/selections part and it takes care of the Observer part. You don't have to worry about the observer pattern, the framework does it for you.

QAbstractItemDelegate

Is the base class for the controller of the MVC.
Is the Strategy pattern for painting, editing the elements, ...


QGraphicsScene / QGraphicsView

Are from the "The Graphics View Framework" and is independent of the Model/View framework.
This is also a very powerful framework for the graphics part.

The Scene

QGraphicsScene provides the Graphics View scene. The scene has the following responsibilities:

Providing a fast interface for managing a large number of items Propagating events to each item Managing item state, such as selection and focus handling Providing untransformed rendering functionality; mainly for printing

The View

QGraphicsView provides the view widget, which visualizes the contents of a scene. You can attach several views to the same scene, to provide several viewports into the same data set


If you want a Model to be visible in a QGraphicsView than you will have to write your own view based on the QAbstractItemView.
Take a QGraphicsView as view port widget QAbstractScrollArea::setViewport(QWidget * widget)) and then you can

  • add QAbstractItemView::rowsInserted,
  • remove QAbstractItemView::rowsAboutToBeRemoved
  • and change QAbstractItemView::dataChanged

the items in the scene. Don't forget to take care of the reset an layout change events.

13
ответ дан 2 December 2019 в 21:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: