Редактирование: The Panel Stack Pattern

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия Ваш текст
Строка 1: Строка 1:
-
{{Панель навигации по Qt Quarterly|Выпуск 27}}
+
{{Панель навигации по Qt Quarterly|Выпуск 28}}
by Johan Thelin
by Johan Thelin
Строка 11: Строка 11:
In this article, I will present a basic pattern that I've been using when implementing this type of applications. I call it a pattern because each of these systems that I've come across has its own peculiarities and it is hard to make them all in one mould.
In this article, I will present a basic pattern that I've been using when implementing this type of applications. I call it a pattern because each of these systems that I've come across has its own peculiarities and it is hard to make them all in one mould.
 +
<div id="thestack"></div>
 +
===The Stack===
-
 
-
===The Stack===
 
All these systems are based around full screen dialogs&mdash;I choose to call these panels. Most of these panels are fairly static and can thus be created at start-up. To avoid having to create them all at once, the singleton pattern can be used. This postpones the creation of panels until they are first used, but prevents them from being created more than once.  
All these systems are based around full screen dialogs&mdash;I choose to call these panels. Most of these panels are fairly static and can thus be created at start-up. To avoid having to create them all at once, the singleton pattern can be used. This postpones the creation of panels until they are first used, but prevents them from being created more than once.  
Строка 49: Строка 49:
</source>  
</source>  
The actual singleton implementation is made in each subclass of <tt>AbstractPanel</tt>. That is also where the <tt>showPanel()</tt> method is added. I have left out a virtual <tt>showPanel()</tt> method, as different panels need different arguments when being initialized.
The actual singleton implementation is made in each subclass of <tt>AbstractPanel</tt>. That is also where the <tt>showPanel()</tt> method is added. I have left out a virtual <tt>showPanel()</tt> method, as different panels need different arguments when being initialized.
 +
<div id="anexample"></div>
 +
===An Example===
-
 
-
===An Example===
 
Let's continue by looking at an example. In this case, a VCR control panel. It consists of four panels: the main menu, the live panel (holding the play, pause and stop buttons), the recordings panel (allowing the user to manage schedules for recording), and finally, the recording details panel (letting the user configure a given schedule for recording).
Let's continue by looking at an example. In this case, a VCR control panel. It consists of four panels: the main menu, the live panel (holding the play, pause and stop buttons), the recordings panel (allowing the user to manage schedules for recording), and finally, the recording details panel (letting the user configure a given schedule for recording).
Строка 159: Строка 159:
</source>  
</source>  
Just wrapping a widget in another widget is not a good way to move forward. However, if we add some functionality to the panel stack we can start to make some gains. We'll examine one way to do this in the next section.
Just wrapping a widget in another widget is not a good way to move forward. However, if we add some functionality to the panel stack we can start to make some gains. We'll examine one way to do this in the next section.
 +
<div id="keepinghistoryinthestack"></div>
 +
===Keeping History in the Stack===
-
 
-
===Keeping History in the Stack===
 
In the previous example, we built a set of panels that are navigated according to a static pattern. Clicking '''Back''' when in the recordings panel always leads to the main menu, and so on. This is all very well in most small systems, but it means that we cannot reuse panels in different places in the navigation tree.
In the previous example, we built a set of panels that are navigated according to a static pattern. Clicking '''Back''' when in the recordings panel always leads to the main menu, and so on. This is all very well in most small systems, but it means that we cannot reuse panels in different places in the navigation tree.
Строка 223: Строка 223:
The idea here is that a panel can appear both as a result of its <tt>showPanel()</tt> method being called and from a panel stack event, resulting from a call to <tt>home()</tt> or <tt>back()</tt>. In the latter case the panel needs to know that it is about to be shown so that it can update its contents. For example, the recordings panel updates its list of recordings here.
The idea here is that a panel can appear both as a result of its <tt>showPanel()</tt> method being called and from a panel stack event, resulting from a call to <tt>home()</tt> or <tt>back()</tt>. In the latter case the panel needs to know that it is about to be shown so that it can update its contents. For example, the recordings panel updates its list of recordings here.
 +
<div id="pullingapartthestack"></div>
 +
===Pulling Apart the Stack===
-
 
-
===Pulling Apart the Stack===
 
We now have a method that we know is called every time a new panel is about to be shown. So, why not use it to update some common parts of the user interface. For instance, if a title bar is a part of every panel, why not place it in the panel stack and add a virtual method called <tt>titleText()</tt> to each abstract panel?
We now have a method that we know is called every time a new panel is about to be shown. So, why not use it to update some common parts of the user interface. For instance, if a title bar is a part of every panel, why not place it in the panel stack and add a virtual method called <tt>titleText()</tt> to each abstract panel?
<source lang="cpp-qt">
<source lang="cpp-qt">
Строка 251: Строка 251:
</source>  
</source>  
There are numerous other elements that can be added to the panel stack to form a common infrastructure. If nothing else, '''Back''' and '''Home''' buttons, and perhaps a couple of shortcut buttons leading to specific forms. The buttons can then be hidden and shown by adding virtual methods such as <tt>hasBack()</tt> and <tt>hasHome()</tt> to the <tt>AbstractPanel</tt> class.  
There are numerous other elements that can be added to the panel stack to form a common infrastructure. If nothing else, '''Back''' and '''Home''' buttons, and perhaps a couple of shortcut buttons leading to specific forms. The buttons can then be hidden and shown by adding virtual methods such as <tt>hasBack()</tt> and <tt>hasHome()</tt> to the <tt>AbstractPanel</tt> class.  
-
 
+
<div id="morethroughthestack"></div>
===More through the Stack===
===More through the Stack===
 +
The stacked approach does not only allow for the transfer of information from the panels to the stack. It can work the other way around, too. This is very helpful when dealing with systems with rudimentary control methods.  
The stacked approach does not only allow for the transfer of information from the panels to the stack. It can work the other way around, too. This is very helpful when dealing with systems with rudimentary control methods.  
Строка 261: Строка 262:
The source code for the example described in this article can be obtained [http://doc.trolltech.com/qq/qq27-panelstack.zip from the ''Qt Quarterly'' Web site].
The source code for the example described in this article can be obtained [http://doc.trolltech.com/qq/qq27-panelstack.zip from the ''Qt Quarterly'' Web site].
 +
 +
[[Категория:Qt Издания]]

Пожалуйста, обратите внимание, что все ваши добавления могут быть отредактированы или удалены другими участниками. Если вы не хотите, чтобы кто-либо изменял ваши тексты, не помещайте их сюда.
Вы также подтверждаете, что являетесь автором вносимых дополнений, или скопировали их из источника, допускающего свободное распространение и изменение своего содержимого (см. Wiki.crossplatform.ru:Авторское право). НЕ РАЗМЕЩАЙТЕ БЕЗ РАЗРЕШЕНИЯ ОХРАНЯЕМЫЕ АВТОРСКИМ ПРАВОМ МАТЕРИАЛЫ!


Шаблоны, использованные на текущей версии страницы: