Implementing the File Menu

本文介绍了Qt中对话框的使用方法,包括模态与非模态对话框的区别及实现方式,并展示了如何通过QTableWidget定位单元格。此外,还讨论了如何设置QApplication在最后一个窗口关闭后的行为。


当最后一个窗体被关闭,应用程序就结束了。QApplication' 的quitOnLastWindowClosed 属性设为 false,程序会一直运行,直到我们调用QApplication::quit()

一个对话框如果调用 show() 就是非模态的(如果之前调用了setModal() 则是模态的 );如果调用exec() 则是模态的。

QDialog::exec() 返回true (if the dialog is accepted) 或false (otherwise),通常OK 按钮连接 accept() ,Cancel 连接 reject()

QTableWidget::setCurrentCell() 接受两个参数,一个是行index, 一个是列index

QString::mid() 返回从start position 到尾部的字符串。

void MainWindow::goToCell()
{
    GoToCellDialog *dialog = new GoToCellDialog(this);
    if (dialog->exec()) {
        QString str = dialog->lineEdit->text().toUpper();
        spreadsheet->setCurrentCell(str.mid(1).toInt() - 1,
                                    str[0].unicode() - 'A');
    }
    delete dialog;
}


模态对话框一般用完就销毁

 

 

 

 

 

 

HW11 - Challenge Description Instructions Testing Submit Description For this Homework, you will be implementing a search engine using Network IO and JOptionPanes. You will use two classes: SearchClient.java and SearchServer.java. We encourage you to practice searching for text during your testing. At several points in this assignment, we will share important reminders of how to organize your solution. Organization is a critical aspect of designing applications with these tools. If Google tried to load the entirety of the Internet on your client instance of Google Chrome every time you performed a search, do you think it would be a popular application? Alternatively, if a bank stored everyone's passwords in the files of a mobile app, do you think it would be secure for very long? These decisions are vital to ensuring that you develop safe, reliable, and secure applications in the real world. Note: 5 points of your Challenge grade is based on Coding Style. You will need to follow the standards described on Brightspace. Use the "Run" button to check your Coding Style without using a submission. Instructions All input and output should be done through JOptionPane dialogs. Any input and output conducted via the terminal will not receive points. Note: GUI applications will not run on Vocareum. Test them locally! The user will be able to enter the host name and port number through a JOptionPane. Once connected, the user can search for text and will be given the results in another JOptionPane. From there, the user can elect to open one of the results to review the full description. The specific details of the message prompt are up to you. The searching process involves sequential steps. The server, when started, will load a database file called "searchDatabase.txt" that contains the searchable data (file format details included below). Next, the user will be prompted to enter a text string as their search. The input string will be sent to the server. The server will return the titles of every page where the title or description contains the searched value. On the client side, the titles sent by the server will be displayed in a dropdown menu. The user will select one of the options and the index of that selection will be sent back to the server. The server will return the description of the requested page. The client class will handle displaying the GUI, accepting user input, and displaying the results. The server will handle all processing. Your implementation must follow this organization to receive credit. searchDatabase.txt format The file will be formatted with rows as follows: PageID;Page Title;Page Description. For example: 1;Local birds;There are many birds of note in the Lafayette area. Each has unique characteristics such as a particular song or flight pattern. 2;Programming languages;There are many different types of programming languages. Java is a high-level, object-oriented language. You can assume that the only semi-colons present in the file will be separating the entries in each row. An example file is included in the starter code. Implementation Requirements Your program must perform the following in order: Welcome the user Prompt the user to enter a host name and port number (you may do this separately or together). If the connection is not established successfully, show an error message and end the program. Show a connection established message. Ask the user to enter their search text. Display a dropdown menu with the results of the search. If the search did not return any results, display an error and continue to step 7. If the search returned at least one result, display the dropdown and allow the user to select one. Proceed to step 6. Display the page description of the title selected in the previous step. Ask the user if they'd like to search again. If no, continue to step 8. If yes, return to step 4. Display a farewell message. Exit The specifics of the look and feel, the text messages you use (except when specified), and the types of dialogs are all up to you. Keep in mind that all your decisions should be logical and design oriented. Hint: Remember, the server needs to be running before you run the client. Notes Your program should handle a situation where the user selects cancel on any option where it is available, or exits the panel. The client accepts user input and displays the GUI. The server processes the input and returns the results. Solutions that do not organize the implementation appropriately will not receive credit. The server should accept one connection from a user at a time. The server should run in an infinite loop until stopped. The Intellij GUI Designer (or any other shortcut tool) is not allowed for any CS 18000 assignment. If there are .form files in your submission, it will not be graded. This assignment must use JOptionPane GUIs. A solution that does not do so will not receive credit. You can choose which port number to use in the Server. Include the number in the client and server class comments. Use "localhost" for the host name. Your solution must handle all exceptions and errors. You will not be able to run your solution on Vocareum. This is expected. As long as you submit, you will be graded. Testing Run through the program with sample inputs and verify everything is performing as expected. Submit After testing your solution and verifying that it meets the requirements described in this document, you can submit on Vocareum. Your work will be graded as soon as possible after the late submission deadline.
07-30
In this task, you will design and implement a user-driven vocabulary management system that supports interaction from different types of users (e.g., readers and admins). This task simulates a real-world collaborative environment, where access control and data integrity are critical. 🧩 Task Objective You are required to implement the following two classes: Role: defines the role of a user, including their name, access level, and identity information. RoleBasedVocabSys: manages user login, menu display, command execution, and interaction with the TextProcessor object. The program should simulate a terminal-like experience for different types of users, controlling what they can see and what actions they can perform. 👥 User Roles The system supports two user roles: Reader: Can log in and view the vocabulary. Can view the top 10 and bottom 10 most frequent words. Cannot update or modify any part of the vocabulary. check the examples below for reference. Admin: Has all the permissions of the reader. Can update the vocabulary by adding new files or removing existing ones. Has full access to the vocabulary update methods from TextProcessor. User credentials and access roles are provided as the varaiable users_info from the util.py module. in scaffold. 📋 Task Requirements You must: Implement the Role class, which should: Store and return the user’s username, display name, and access level (e.g., "reader", "admin"). Provide getter methods: get_user_name(), get_access(), get_name(). Implement the RoleBasedVocabSys class, which should: Handle login and logout. Display different menus depending on whether a user is logged in and their access level. Call TextProcessor functions (from Task 7) to manage the vocabulary. Enforce role-based access control (e.g., only admins can update vocabularies). Use the provided attributes and method names in the scaffold. Do not rename or remove any predefined code blocks. Implement menu-based navigation where users can choose options via standard input: Exit the system. Login or Logout. View the top 10 or bottom 10 frequent words. Update vocabulary by adding/removing files (admin only). You may write additional helper functions or methods as needed. 🧠 Additional Notes The vocabulary is loaded and managed via the TextProcessor object created in the constructor. The files to be added/removed are fixed as data/for_admin/excluded.csv data/add.csv and data/delete.csv for this exercise, but you may generalize it in future tasks. All user input should be validated using verify_user_choice. The system should loop until the user chooses to exit. Examples Example 1a: interface when starting the program Welcome to the Mark system v0.0! Please Login: 1.Exit 2.Login Enter your choice: Example 1b: unlimited attemps for invalid users inputs Welcome to the Mark system v0.0! Please Login: 1.Exit 2.Login Enter your choice: ewfwef Enter your choice: edf Enter your choice: 3 Enter your choice: 4 ... Enter your choice: Example 2a: correct login credential for reader Welcome to the Mark system v0.0! Please Login: 1.Exit 2.Login Please key your account name: Jueqing Please key your password: jueqing123 Welcome Jueqing Lu Please choose one option below: 1.Exit 2.Logout/Re-Login 3.Show top 10 frequency vocabularies 4.Show last 10 frequency vocabularies Enter your choice: Example 2b: correct login credential for admin Welcome to the Mark system v0.0! Please Login: 1.Exit 2.Login Please key your account name: Trang Please key your password: trang123 Welcome Trang Vu Please choose one option below: 1.Exit 2.Logout/Re-Login 3.Show top 10 frequency vocabularies 4.Show last 10 frequency vocabularies 5.Updating Vobulary for adding 6.Updating Vobulary for excluding Enter your choice:
最新发布
09-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值